aboutsummaryrefslogtreecommitdiff
path: root/tests/server
diff options
context:
space:
mode:
authorMarkus Elfring <elfring@users.sourceforge.net>2015-03-11 17:41:01 +0100
committerDaniel Stenberg <daniel@haxx.se>2015-03-16 12:13:56 +0100
commit29c655c0a6affc0359e499162e8308663eb4d04f (patch)
treeed6b1fc761dee6623ec1b312cc53dc3b661c1550 /tests/server
parent059b3a5770075315dbc843b9285a1cdec82c12d5 (diff)
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>
Diffstat (limited to 'tests/server')
-rw-r--r--tests/server/getpart.c9
-rw-r--r--tests/server/rtspd.c44
-rw-r--r--tests/server/sws.c44
-rw-r--r--tests/server/tftpd.c6
4 files changed, 33 insertions, 70 deletions
diff --git a/tests/server/getpart.c b/tests/server/getpart.c
index fb86596e7..f773dd058 100644
--- a/tests/server/getpart.c
+++ b/tests/server/getpart.c
@@ -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;
}
diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c
index 72422ecf5..0293f59cf 100644
--- a/tests/server/rtspd.c
+++ b/tests/server/rtspd.c
@@ -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;
diff --git a/tests/server/sws.c b/tests/server/sws.c
index 1adbeccda..094a92d64 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -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;
diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c
index 25557932f..cef129f2e 100644
--- a/tests/server/tftpd.c
+++ b/tests/server/tftpd.c
@@ -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! */