Hello,
I use a structure type that I want to remove from memory at the end of the program. I came up with something but since i'm new to C, I was wondering, does this code free all the memory used?
Thanks in advance.
Side question: is there any way to check the memory that my program uses, except for printing to the screen the value of the pointers and such? this way I could figure out by my self if my code is good.
Code:struct _cmdline { int argc; char** argv; // arguments variables (strings array) char* outRedir; // output redirection file (NULL is none) int amp; }; typedef struct _cmdline cmdline;Code:void free_cmdline (cmdline** ptr){ int i; for (i=0; i<(*ptr)->argc; i++){ free( (*ptr)->argv[i] ); (*ptr)->argv[i]=NULL; } free( (*ptr)->argv ); (*ptr)->argv=NULL; free( (*ptr)->outRedir ); (*ptr)->outRedir=NULL; free( *ptr ); (*ptr)=NULL; }



2Likes
LinkBack URL
About LinkBacks


