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 <elfring@users.sourceforge.net>
This commit is contained in:
Markus Elfring 2015-03-11 17:41:01 +01:00 committed by Daniel Stenberg
parent 059b3a5770
commit 29c655c0a6
40 changed files with 152 additions and 339 deletions

View file

@ -83,8 +83,7 @@ int test(char *URL)
test_cleanup:
curl_slist_free_all(slist);
if(newURL)
free(newURL);
free(newURL);
curl_easy_cleanup(curl);
curl_global_cleanup();

View file

@ -159,8 +159,7 @@ test_cleanup:
if(sdpf)
fclose(sdpf);
if(stream_uri)
free(stream_uri);
free(stream_uri);
if(custom_headers)
curl_slist_free_all(custom_headers);

View file

@ -115,9 +115,7 @@ test_cleanup:
if(idfile)
fclose(idfile);
if(stream_uri)
free(stream_uri);
free(stream_uri);
curl_easy_cleanup(curl);
curl_global_cleanup();

View file

@ -102,9 +102,7 @@ int test(char *URL)
}
test_cleanup:
if(stream_uri)
free(stream_uri);
free(stream_uri);
curl_easy_cleanup(curl);
curl_global_cleanup();

View file

@ -195,9 +195,7 @@ int test(char *URL)
}
test_cleanup:
if(stream_uri)
free(stream_uri);
free(stream_uri);
if(protofile)
fclose(protofile);

View file

@ -165,8 +165,7 @@ test_cleanup:
if(paramsf)
fclose(paramsf);
if(stream_uri)
free(stream_uri);
free(stream_uri);
if(custom_headers)
curl_slist_free_all(custom_headers);

View file

@ -357,10 +357,8 @@ test_cleanup:
fclose(hd_src);
/* free local memory */
if(sockets.read.sockets)
free(sockets.read.sockets);
if(sockets.write.sockets)
free(sockets.write.sockets);
free(sockets.read.sockets);
free(sockets.write.sockets);
return res;
}

View file

@ -209,8 +209,7 @@ static int decodedata(char **buf, /* dest buffer */
** let's just assume it is an OOM condition, currently we have
** no input for this function that decodes to zero length data.
*/
if(buf64)
free(buf64);
free(buf64);
return GPE_OUT_OF_MEMORY;
}
@ -435,15 +434,13 @@ int getpart(char **outbuf, size_t *outlen,
} /* while */
if(buffer)
free(buffer);
free(buffer);
if(error != GPE_OK) {
if(error == GPE_END_OF_FILE)
error = GPE_OK;
else {
if(*outbuf)
free(*outbuf);
free(*outbuf);
*outbuf = NULL;
*outlen = 0;
}

View file

@ -523,8 +523,7 @@ static int ProcessRequest(struct httprequest *req)
} while(ptr && *ptr);
logmsg("Done parsing server commands");
}
if(cmd)
free(cmd);
free(cmd);
}
}
else {
@ -993,8 +992,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(got_exit_signal) {
if(ptr)
free(ptr);
free(ptr);
return -1;
}
@ -1005,8 +1003,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file");
if(ptr)
free(ptr);
free(ptr);
return 0;
}
else {
@ -1015,18 +1012,15 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
fclose(stream);
if(error) {
logmsg("getpart() failed with error: %d", error);
if(ptr)
free(ptr);
free(ptr);
return 0;
}
}
}
if(got_exit_signal) {
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
@ -1050,10 +1044,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", RESPONSE_DUMP);
logmsg("couldn't create logfile: " RESPONSE_DUMP);
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
@ -1110,28 +1102,22 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
RESPONSE_DUMP, error, strerror(error));
if(got_exit_signal) {
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
responsesize-count, responsesize);
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
logmsg("Response sent (%zu bytes) and written to " RESPONSE_DUMP,
responsesize);
if(ptr)
free(ptr);
free(ptr);
if(cmdsize > 0 ) {
char command[32];
@ -1169,9 +1155,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
ptr = NULL;
} while(ptr && *ptr);
}
if(cmd)
free(cmd);
free(cmd);
req->open = persistant;
prevtestno = req->testno;

View file

@ -442,8 +442,7 @@ static int parse_servercmd(struct httprequest *req)
else
break;
}
if(orgcmd)
free(orgcmd);
free(orgcmd);
}
return 0; /* OK! */
@ -1126,8 +1125,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(got_exit_signal) {
if(ptr)
free(ptr);
free(ptr);
return -1;
}
@ -1137,8 +1135,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg(" [4] Error opening file: %s", filename);
if(ptr)
free(ptr);
free(ptr);
return 0;
}
else {
@ -1147,18 +1144,15 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
fclose(stream);
if(error) {
logmsg("getpart() failed with error: %d", error);
if(ptr)
free(ptr);
free(ptr);
return 0;
}
}
}
if(got_exit_signal) {
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
@ -1181,10 +1175,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg(" [5] Error opening file: %s", responsedump);
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
@ -1228,28 +1220,22 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
responsedump, error, strerror(error));
if(got_exit_signal) {
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
responsesize-count, responsesize);
if(ptr)
free(ptr);
if(cmd)
free(cmd);
free(ptr);
free(cmd);
return -1;
}
logmsg("Response sent (%zu bytes) and written to %s",
responsesize, responsedump);
if(ptr)
free(ptr);
free(ptr);
if(cmdsize > 0 ) {
char command[32];
@ -1285,9 +1271,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
ptr = NULL;
} while(ptr && *ptr);
}
if(cmd)
free(cmd);
free(cmd);
req->open = use_gopher?FALSE:persistant;
prevtestno = req->testno;

View file

@ -876,8 +876,7 @@ int main(int argc, char **argv)
memset(&test, 0, sizeof(test));
if (do_tftp(&test, tp, n) < 0)
break;
if(test.buffer)
free(test.buffer);
free(test.buffer);
}
sclose(peer);
peer = CURL_SOCKET_BAD;
@ -1089,8 +1088,7 @@ static int parse_servercmd(struct testcase *req)
else
break;
}
if(orgcmd)
free(orgcmd);
free(orgcmd);
}
return 0; /* OK! */

View file

@ -65,9 +65,7 @@ static void unit_stop( void )
Curl_freeaddrinfo(data_node->addr);
free(data_node);
}
if (data_key)
free(data_key);
free(data_key);
Curl_hash_destroy(hp);
curl_easy_cleanup(data);