From 29c655c0a6affc0359e499162e8308663eb4d04f Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Wed, 11 Mar 2015 17:41:01 +0100 Subject: Bug #149: Deletion of unnecessary checks before calls of the function "free" The function "free" is documented in the way that no action shall occur for a passed null pointer. It is therefore not needed that a function caller repeats a corresponding check. http://stackoverflow.com/questions/18775608/free-a-null-pointer-anyway-or-check-first This issue was fixed by using the software Coccinelle 1.0.0-rc24. Signed-off-by: Markus Elfring --- docs/examples/fopen.c | 12 +++--------- docs/examples/getinmemory.c | 3 +-- docs/examples/postinmemory.c | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) (limited to 'docs') diff --git a/docs/examples/fopen.c b/docs/examples/fopen.c index 3d2a81773..4089bb433 100644 --- a/docs/examples/fopen.c +++ b/docs/examples/fopen.c @@ -210,9 +210,7 @@ static int use_buffer(URL_FILE *file,int want) /* sort out buffer */ if((file->buffer_pos - want) <=0) { /* ditch buffer - write will recreate */ - if(file->buffer) - free(file->buffer); - + free(file->buffer); file->buffer=NULL; file->buffer_pos=0; file->buffer_len=0; @@ -302,9 +300,7 @@ int url_fclose(URL_FILE *file) break; } - if(file->buffer) - free(file->buffer);/* free any allocated buffer space */ - + free(file->buffer);/* free any allocated buffer space */ free(file); return ret; @@ -435,9 +431,7 @@ void url_rewind(URL_FILE *file) curl_multi_add_handle(multi_handle, file->handle.curl); /* ditch buffer - write will recreate - resets stream pos*/ - if(file->buffer) - free(file->buffer); - + free(file->buffer); file->buffer=NULL; file->buffer_pos=0; file->buffer_len=0; diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 1608ec551..a1c21404d 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -106,8 +106,7 @@ int main(void) /* cleanup curl stuff */ curl_easy_cleanup(curl_handle); - if(chunk.memory) - free(chunk.memory); + free(chunk.memory); /* we're done with libcurl, so clean it up */ curl_global_cleanup(); diff --git a/docs/examples/postinmemory.c b/docs/examples/postinmemory.c index cd2bd13fb..3afac4b2f 100644 --- a/docs/examples/postinmemory.c +++ b/docs/examples/postinmemory.c @@ -101,8 +101,7 @@ int main(void) /* always cleanup */ curl_easy_cleanup(curl); - if(chunk.memory) - free(chunk.memory); + free(chunk.memory); /* we're done with libcurl, so clean it up */ curl_global_cleanup(); -- cgit v1.2.3