{"thread":{"id":"20463","subject":"[PATCH] Check return value of ftruncate call in http.c. Remove possible mem leak","startedAt":"2009-08-08T05:38:01Z","lastAt":"2009-08-10T01:54:29Z","messageCount":2,"participants":["Jeff Lasslett","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"119954","messageId":"1249709881-31334-1-git-send-email-jeff.lasslett@gmail.com","threadId":"20463","inReplyTo":null,"subject":"[PATCH] Check return value of ftruncate call in http.c. Remove possible mem leak","fromName":"Jeff Lasslett","fromEmail":"jeff.lasslett@gmail.com","sentAt":"2009-08-08T05:38:01Z","receivedAt":"2009-08-08T05:38:01Z","isPatch":true,"sender":{"key":"jeff.lasslett@gmail.com","avatar":null},"body":"In new_http_object_request(), check ftruncate() call return value and\nhandle possible errors.  Remove possible leak of mem pointed to by url.\n\nSigned-off-by: Jeff Lasslett <jeff.lasslett@gmail.com>\n---\n http.c |   12 +++++++++---\n 1 files changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex a2720d5..34a3a35 100644\n--- a/http.c\n+++ b/http.c\n@@ -1098,7 +1098,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \tchar *hex = sha1_to_hex(sha1);\n \tchar *filename;\n \tchar prevfile[PATH_MAX];\n-\tchar *url;\n+\tchar *url = NULL;\n \tint prevlocal;\n \tunsigned char prev_buf[PREV_BUF_SIZE];\n \tssize_t prev_read = 0;\n@@ -1189,7 +1189,11 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \t\tif (prev_posn>0) {\n \t\t\tprev_posn = 0;\n \t\t\tlseek(freq->localfile, 0, SEEK_SET);\n-\t\t\tftruncate(freq->localfile, 0);\n+\t\t\tif (ftruncate(freq->localfile, 0) < 0) {\n+\t\t\t\terror(\"Couldn't truncate temporary file %s for %s: %s\",\n+\t\t\t\t\t  freq->tmpfile, freq->filename, strerror(errno));\n+\t\t\t\tgoto abort;\n+\t\t\t}\n \t\t}\n \t}\n \n@@ -1216,10 +1220,12 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \t\t\t\t CURLOPT_HTTPHEADER, range_header);\n \t}\n \n+\tfree(url);\n \treturn freq;\n \n-\tfree(url);\n abort:\n+\tfree(url);\n+\tfree(freq->url);\n \tfree(filename);\n \tfree(freq);\n \treturn NULL;\n-- \n1.6.4.59.g4d590.dirty\n"},{"id":"120105","messageId":"7vljls5t7u.fsf@alter.siamese.dyndns.org","threadId":"20463","inReplyTo":"1249709881-31334-1-git-send-email-jeff.lasslett@gmail.com","subject":"Re: [PATCH] Check return value of ftruncate call in http.c. Remove possible mem leak","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-10T01:54:29Z","receivedAt":"2009-08-10T01:54:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff Lasslett <jeff.lasslett@gmail.com> writes:\n\n> In new_http_object_request(), check ftruncate() call return value and\n> handle possible errors.  Remove possible leak of mem pointed to by url.\n\nAre you assuming that everybody is running libcurl 7.17.0 or later?\nBefore that version strings given to easy_setopt() were not copied and you\nneeded to keep them around.\n\nI think freeing url is fine but you would probably need to then give\nfreq->url to easy_setopt(CURLOPT_URL) if you wanted to do so.\n"}]}