Crusty
Lifer
I have the following code
All of that works as expected, i can build my arrays and everything is dandy. Then I come along and call a destroy function like such
Now here is where my problem is. Through one execution of the program there are many cycles of init()/destroy() before execution is finally terminated. After the first call to destroy() I can still access all the memory pointed to by blist and see all the values in the struct within the array. I can not do this for alist.
I first noticed this after the second call to init() when the memory still had all the old values from the first cycle of init()/destroy(). I popped into gdb and verified that free in fact is not doing anything to the memory, and all calls to malloc/memset on the pointer blist have no effects.
Any ideas why my blist array is not being set to all 0's after the 2nd call to init()?
Code:
typedef struct _a a;
typedef struct _b b;
struct _a {
a *next_a;
b *root;
};
struct _b {
a *head;
};
a *alist;
b *blist;
void init() {
alist = malloc(sizeof(a)*1000);
assert(alist);
memset(alist,0,sizeof(a)*1000);
blist = malloc(sizeof(b)*1000);
assert(blist);
memset(blist,0,sizeof(b)*1000);
}
All of that works as expected, i can build my arrays and everything is dandy. Then I come along and call a destroy function like such
Code:
void destroy() {
free(alist);
free(blist);
}
Now here is where my problem is. Through one execution of the program there are many cycles of init()/destroy() before execution is finally terminated. After the first call to destroy() I can still access all the memory pointed to by blist and see all the values in the struct within the array. I can not do this for alist.
I first noticed this after the second call to init() when the memory still had all the old values from the first cycle of init()/destroy(). I popped into gdb and verified that free in fact is not doing anything to the memory, and all calls to malloc/memset on the pointer blist have no effects.
Any ideas why my blist array is not being set to all 0's after the 2nd call to init()?
Last edited: