Free Nothing
-
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
What is NULL
#define
d as? :-D -
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
-
What's the problem? 1. Remove all references 2. Invoke the GC ;P
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 3 out nowAaaah, yeah... NULL could be a collection of references to be freed. :-D
-
Aaaah, yeah... NULL could be a collection of references to be freed. :-D
-
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
flag = NULL sets it to point to nothing. This makes the memory location lost. flag = (data_type*)malloc(sizeof(data_type)); This returns address of the memory allocated by malloc and assignes the address value to flag - something like flag = 0x2345cf. This is a valid address it is pointing to. When you say flag = NULL, flag points to nothing, then you cannot free flag because you cannot free something that does not exist. So first free(flag); then set flag = NULL; i.e. just change the sequence to- free(flag); flag = NULL; free(fval); fval = NULL; :)
-
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
:-D
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
In an effort to gain more memory by showing negative used space!
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson -
flag = NULL sets it to point to nothing. This makes the memory location lost. flag = (data_type*)malloc(sizeof(data_type)); This returns address of the memory allocated by malloc and assignes the address value to flag - something like flag = 0x2345cf. This is a valid address it is pointing to. When you say flag = NULL, flag points to nothing, then you cannot free flag because you cannot free something that does not exist. So first free(flag); then set flag = NULL; i.e. just change the sequence to- free(flag); flag = NULL; free(fval); fval = NULL; :)
:laugh: You didn't take your coffee this morning ? Did you forget to read the title of the forum ?
Cédric Moonen Software developer
Charting control [v1.4] -
:laugh: You didn't take your coffee this morning ? Did you forget to read the title of the forum ?
Cédric Moonen Software developer
Charting control [v1.4] -
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
-
reminds me of the NRA and gun advocacy... it's the shooter not the gun it's the programmer not the language
David
-
reminds me of the NRA and gun advocacy... it's the shooter not the gun it's the programmer not the language
David
Oh, great, now I have an opening for something I was thinking yesterday: A song that was playing used the phrase, "the wrong end of a gun". Does the anti-gun crew consider both ends of a gun to be "wrong"? :confused:
-
Previously in the code both flag and fval were malloc'd
flag = NULL;
free(flag);fval = NULL;
free(fval);this thing looks like it was written by an epileptic ferret Dave Kreskowiak
Too bad 'free()' wasn't defined as returning a (void *). In that case, the code could have been written as: flag = free(flag); In case of any error other than a null pointer being passed in, free() could return the passed-in pointer. Similar behavior could have been used with fclose() [return a (FILE*)] and other such functions that destroy the object whose pointer is passed to them. Oh well, only a few decades too late now.... Where's my time machine?