Commit 29c655c0 authored by Markus Elfring's avatar Markus Elfring Committed by Daniel Stenberg
Browse files

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: default avatarMarkus Elfring <elfring@users.sourceforge.net>
parent 059b3a57
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -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);

    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);

  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);

    file->buffer=NULL;
    file->buffer_pos=0;
    file->buffer_len=0;
+1 −2
Original line number Diff line number Diff line
@@ -106,7 +106,6 @@ int main(void)
  /* cleanup curl stuff */
  curl_easy_cleanup(curl_handle);

  if(chunk.memory)
  free(chunk.memory);

  /* we're done with libcurl, so clean it up */
+1 −2
Original line number Diff line number Diff line
@@ -101,7 +101,6 @@ int main(void)
    /* always cleanup */
    curl_easy_cleanup(curl);

    if(chunk.memory)
    free(chunk.memory);

    /* we're done with libcurl, so clean it up */
+1 −2
Original line number Diff line number Diff line
@@ -186,7 +186,6 @@ void Curl_resolver_cancel(struct connectdata *conn)
 */
static void destroy_async_data (struct Curl_async *async)
{
  if(async->hostname)
  free(async->hostname);

  if(async->os_specific) {
+2 −5
Original line number Diff line number Diff line
@@ -190,7 +190,6 @@ void destroy_thread_sync_data(struct thread_sync_data * tsd)
    free(tsd->mtx);
  }

  if(tsd->hostname)
  free(tsd->hostname);

  if(tsd->res)
@@ -364,9 +363,7 @@ static void destroy_async_data (struct Curl_async *async)
  }
  async->os_specific = NULL;

  if(async->hostname)
  free(async->hostname);

  async->hostname = NULL;
}

Loading