mirror of
https://github.com/curl/curl.git
synced 2026-08-08 22:54:36 +03:00
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:
parent
059b3a5770
commit
29c655c0a6
40 changed files with 152 additions and 339 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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! */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue