easy question about free()



Hi,

if I have declared:

typedef struct something_big_struct Something_Big;

struct something_big_struct{
<lots of stuff>
Something_Big *a_big_thing;
};

and I allocate some memory:

SomethingBig *bigPtr;

bigPtr = malloc(sizeof(Something_Big));

After I'm finnished with bigPtr do I need to free a_big_thing separately?
ie do I need to free(bigPtr -> a_big_thing) before I free(bigPtr)?

Thanks for your help

Regards

Michael



.



Relevant Pages

  • Re: easy question about free()
    ... and I allocate some memory: ... SomethingBig *bigPtr; ... failing to do so will cause a memory leak. ...
    (comp.lang.c)
  • Re: easy question about free()
    ... and I allocate some memory: ... SomethingBig *bigPtr; ... another structure that contains a struct something_big_struct and some ... because you didn't show us how you provided memory to ...
    (comp.lang.c)
  • Re: easy question about free()
    ... and I allocate some memory: ... SomethingBig *bigPtr; ... Anything you've requested with malloc() needs a free. ... of a list member before you can free the member itself. ...
    (comp.lang.c)
  • Re: easy question about free()
    ... and I allocate some memory: ... SomethingBig *bigPtr; ... need to free it before freeing bigPtr or you will have a memory leak. ...
    (comp.lang.c)
  • Re: easy question about free()
    ... and I allocate some memory: ... SomethingBig *bigPtr; ...
    (comp.lang.c)