Today I learned a new trick, consisting of completing a structure with an array of zero length to allow the array to be dynamically evaluated as needed. This is very convenient and helps to save a good amount of memory when I want to determine the amount of space that my structure will consume at runtime, and not compile time.
Using them works fine; then I remembered that I needed to free the allocated memory, so I just threw away the free (structure); there, but to my horror, which threw me an error:
*** glibc detected *** ./program: free(): invalid next size (fast): <address> ======= Backtrace: ========= <omitted> ======= Memory Map: ======== <omitted>
Here is a simple example in poorly formatted code:
struct Stuff { int size;
And I get an error on free (ptr);
Any ideas?
source share