{"thread":{"id":"1453","subject":"[PATCH 0/4] Plug some more memory leaks in git","startedAt":"2005-08-08T18:43:32Z","lastAt":"2005-08-08T18:46:58Z","messageCount":5,"participants":["Sergey Vlasov"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"6941","messageId":"20050808184332.GA5789@procyon.home","threadId":"1453","inReplyTo":null,"subject":"[PATCH 0/4] Plug some more memory leaks in git","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-08-08T18:43:32Z","receivedAt":"2005-08-08T18:43:32Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"Hello!\n\nThis set of patches fixes some more memory leaks which I have found in\ngit.  Especially the write_sha1_to_fd() leak was noticeable when\nrunning git-ssh-push.\n\n-- \nSergey Vlasov\n"},{"id":"6942","messageId":"20050808184443.GB5789@procyon.home","threadId":"1453","inReplyTo":"20050808184332.GA5789@procyon.home","subject":"[PATCH 1/4] Plug memory leak in read_object_with_reference()","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-08-08T18:44:43Z","receivedAt":"2005-08-08T18:44:43Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"[PATCH] Plug memory leak in read_object_with_reference()\n\nWhen following a reference, read_object_with_reference() did not free the\nintermediate object data.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n---\n\n sha1_file.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\nf7d16d6b83698fd7858ad28340b3e87780322261\ndiff --git a/sha1_file.c b/sha1_file.c\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1165,6 +1165,7 @@ void *read_object_with_reference(const u\n \t\t\tfree(buffer);\n \t\t\treturn NULL;\n \t\t}\n+\t\tfree(buffer);\n \t\t/* Now we have the ID of the referred-to object in\n \t\t * actual_sha1.  Check again. */\n \t}\n"},{"id":"6943","messageId":"20050808184536.GC5789@procyon.home","threadId":"1453","inReplyTo":"20050808184332.GA5789@procyon.home","subject":"[PATCH 2/4] Plug memory leak in write_sha1_to_fd()","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-08-08T18:45:36Z","receivedAt":"2005-08-08T18:45:36Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"[PATCH] Plug memory leak in write_sha1_to_fd()\n\nIf the object to write was packed, both its uncompressed and compressed\ndata were leaked.  If the object was not packed, its file was not unmapped.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n---\n\n sha1_file.c |   14 ++++++++++++--\n 1 files changed, 12 insertions(+), 2 deletions(-)\n\n683b9e4bb090c115242392a1f1dc7b1a7c76c4be\ndiff --git a/sha1_file.c b/sha1_file.c\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1297,8 +1297,11 @@ int write_sha1_to_fd(int fd, const unsig\n \tssize_t size;\n \tunsigned long objsize;\n \tint posn = 0;\n-\tvoid *buf = map_sha1_file_internal(sha1, &objsize);\n+\tvoid *map = map_sha1_file_internal(sha1, &objsize);\n+\tvoid *buf = map;\n+\tvoid *temp_obj = NULL;\n \tz_stream stream;\n+\n \tif (!buf) {\n \t\tunsigned char *unpacked;\n \t\tunsigned long len;\n@@ -1314,7 +1317,7 @@ int write_sha1_to_fd(int fd, const unsig\n \t\tmemset(&stream, 0, sizeof(stream));\n \t\tdeflateInit(&stream, Z_BEST_COMPRESSION);\n \t\tsize = deflateBound(&stream, len + hdrlen);\n-\t\tbuf = xmalloc(size);\n+\t\ttemp_obj = buf = xmalloc(size);\n \n \t\t/* Compress it */\n \t\tstream.next_out = buf;\n@@ -1332,6 +1335,7 @@ int write_sha1_to_fd(int fd, const unsig\n \t\twhile (deflate(&stream, Z_FINISH) == Z_OK)\n \t\t\t/* nothing */;\n \t\tdeflateEnd(&stream);\n+\t\tfree(unpacked);\n \t\t\n \t\tobjsize = stream.total_out;\n \t}\n@@ -1348,6 +1352,12 @@ int write_sha1_to_fd(int fd, const unsig\n \t\t}\n \t\tposn += size;\n \t} while (posn < objsize);\n+\n+\tif (map)\n+\t\tmunmap(map, objsize);\n+\tif (temp_obj)\n+\t\tfree(temp_obj);\n+\n \treturn 0;\n }\n \n"},{"id":"6944","messageId":"20050808184613.GD5789@procyon.home","threadId":"1453","inReplyTo":"20050808184332.GA5789@procyon.home","subject":"[PATCH 3/4] Plug memory leak in sha1close()","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-08-08T18:46:13Z","receivedAt":"2005-08-08T18:46:13Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"[PATCH] Plug memory leak in sha1close()\n\nsha1create() and sha1fd() malloc the returned struct sha1file;\nsha1close() should free it.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n---\n\n csum-file.c |    1 +\n 1 files changed, 1 insertions(+), 0 deletions(-)\n\n2207ae4977cbaa84636487ca24bad9d1116f54e0\ndiff --git a/csum-file.c b/csum-file.c\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -45,6 +45,7 @@ int sha1close(struct sha1file *f, unsign\n \t\tsha1flush(f, 20);\n \tif (close(f->fd))\n \t\tdie(\"%s: sha1 file error on close (%s)\", f->name, strerror(errno));\n+\tfree(f);\n \treturn 0;\n }\n \n"},{"id":"6945","messageId":"20050808184658.GE5789@procyon.home","threadId":"1453","inReplyTo":"20050808184332.GA5789@procyon.home","subject":"[PATCH 4/4] Plug memory leak in git-pack-objects","fromName":"Sergey Vlasov","fromEmail":"vsu@altlinux.ru","sentAt":"2005-08-08T18:46:58Z","receivedAt":"2005-08-08T18:46:58Z","isPatch":true,"sender":{"key":"vsu@altlinux.ru","avatar":"https://avatars.githubusercontent.com/u/616082?v=4"},"body":"[PATCH] Plug memory leak in git-pack-objects\n\nfind_deltas() should free its temporary objects before returning.\n\nSigned-off-by: Sergey Vlasov <vsu@altlinux.ru>\n---\n\n pack-objects.c |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\n8b38f80b97affd0d9808b8f276a9e2e04bf03464\ndiff --git a/pack-objects.c b/pack-objects.c\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -382,6 +382,10 @@ static void find_deltas(struct object_en\n \t\tif (idx >= window)\n \t\t\tidx = 0;\n \t}\n+\n+\tfor (i = 0; i < window; ++i)\n+\t\tfree(array[i].data);\n+\tfree(array);\n }\n \n int main(int argc, char **argv)\n"}]}