Dear Board
I am trying to tackle memory allocation/leakage in my program. I have functions which I need to pass arrays of strings and strings. In general the string sizes, array sizes, and sizes of element strings of arrays are not fixed. I prefer to allocate them dynamically unless I could not figure out a way. If I fail at dynamically allocating I might try to allocate these to the maximum size possible but I prefer not to do that horrible thing.
These functions are called repeatedly inside a loop from the beginning to the end of the program existence and in general this program could be up forever. Briefly it's trying to
read a database log file and shipping transactions constantly.
When it works properly it's leaking memory like crazy. When it does not it seg faults.
Question 7.22
The above FAQ says that I must free any pointer that's being called by malloc.
My conclusion is that if that is true then it's impossible to pass dynamically allocated variable to C function.
Neither of the following would work according to this faq.
Consider another faqCode:char *abc (){ char *a; a=malloc(10); *a="abcd"; return a; } void abc(char *a) { a=malloc(10); *a="abcd"; }
Question 7.22
This says that I must also free local pointer. How am I supposed to make above two functions work if I must free what I want to return? Isn't "a" from two examples I posted considered local pointer?