C programming - basic memory management system with leak detection
This reconstructed code implements a basic memory management system with leak detection. Here's an explanation of the different parts: 1. `MemoryNode` structure: This defines a node in a linked list that tracks memory allocations. Each node contains a pointer to the allocated memory, its size, and a pointer to the next node. 2. `custom_malloc` function: - Handles zero-sized allocations by returning NULL. - Allocates memory using the standard `malloc`. - Creates a new `MemoryNode` to track the allocation. - Adds the new node to the front of the linked list. 3. `custom_free` function: - Traverses the linked list to find the node corresponding to the pointer being freed. - Removes the node from the list and frees both the allocated memory and the tracking node. - If the pointer is not found in the list, it prints an error message. 4. `check_leaks` function: - Traverses the linked list of...
Comments
Post a Comment