
Use-After-Free Bugs Explained With Patterns That Prevent Them
A use-after-free reads or writes memory after free released it. See how it happens in C and C++, how ASan reports it and patterns that stop it.
Tag
255 posts

A use-after-free reads or writes memory after free released it. See how it happens in C and C++, how ASan reports it and patterns that stop it.

Compare epoll level-triggered and edge-triggered modes with EPOLLET, see exactly when each reports readiness, and pick the right one for your server.

Run Valgrind Memcheck on your unit tests in CI with exit codes, suppressions and XML output so a new leak or invalid access fails the build before it merges.

Turn on auto-vectorization in GCC and Clang, read the optimization reports that say why a loop was skipped, and set the flags that matter, including -march.

Add an SPI peripheral to a device tree with reg as the chip select, spi-max-frequency and the mode flags, using an MCP3008 ADC as the worked example.

Use struct k_work_delayable with k_work_schedule and k_work_reschedule to run work after a delay, then build a debounce, a timeout and a periodic task.

Use the goto cleanup pattern in C to release files, memory and locks on every error path in reverse order, with a worked example and its limits.

Replace the vendor assembly startup file with one C file for a Cortex-M4: vector table, weak aliases, data copy, bss clear and the GCC flags that keep it safe.

Build a bitstream for an Artix-7 board in Vivado 2024.1 with a non-project Tcl script, an XDC constraint file, implementation and write_bitstream.

Full virtualization runs an unmodified guest, while paravirtualization gives the guest drivers that call the hypervisor. See where virtio and kvmclock fit.

A heap buffer overflow writes past a malloc block into the next chunk. Learn the common causes in C, how AddressSanitizer and Valgrind find them, and fixes.

Write a single-threaded TCP echo server on Linux with epoll_create1, epoll_ctl and epoll_wait, using non-blocking sockets and a clean accept and read loop.