Hello!
This set of patches fixes some more memory leaks which I have found in git. Especially the write_sha1_to_fd() leak was noticeable when running git-ssh-push.
-- Sergey Vlasov
threads / patch / 1453
Subject: [PATCH 0/4] Plug some more memory leaks in git
Hello!
This set of patches fixes some more memory leaks which I have found in git. Especially the write_sha1_to_fd() leak was noticeable when running git-ssh-push.
-- Sergey Vlasov
[PATCH 1/4] Plug memory leak in read_object_with_reference()
[PATCH] Plug memory leak in read_object_with_reference()
When following a reference, read_object_with_reference() did not free the intermediate object data.
Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> ---
sha1_file.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
f7d16d6b83698fd7858ad28340b3e87780322261
diff --git a/sha1_file.c b/sha1_file.c --- a/sha1_file.c +++ b/sha1_file.c @@ -1165,6 +1165,7 @@ void *read_object_with_reference(const u free(buffer); return NULL; } + free(buffer); /* Now we have the ID of the referred-to object in * actual_sha1. Check again. */ }
[PATCH 2/4] Plug memory leak in write_sha1_to_fd()
[PATCH] Plug memory leak in write_sha1_to_fd()
If the object to write was packed, both its uncompressed and compressed data were leaked. If the object was not packed, its file was not unmapped.
Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> ---
sha1_file.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
683b9e4bb090c115242392a1f1dc7b1a7c76c4be
diff --git a/sha1_file.c b/sha1_file.c --- a/sha1_file.c +++ b/sha1_file.c @@ -1297,8 +1297,11 @@ int write_sha1_to_fd(int fd, const unsig ssize_t size; unsigned long objsize; int posn = 0; - void *buf = map_sha1_file_internal(sha1, &objsize); + void *map = map_sha1_file_internal(sha1, &objsize); + void *buf = map; + void *temp_obj = NULL; z_stream stream; + if (!buf) { unsigned char *unpacked; unsigned long len; @@ -1314,7 +1317,7 @@ int write_sha1_to_fd(int fd, const unsig memset(&stream, 0, sizeof(stream)); deflateInit(&stream, Z_BEST_COMPRESSION); size = deflateBound(&stream, len + hdrlen); - buf = xmalloc(size); + temp_obj = buf = xmalloc(size); /* Compress it */ stream.next_out = buf; @@ -1332,6 +1335,7 @@ int write_sha1_to_fd(int fd, const unsig while (deflate(&stream, Z_FINISH) == Z_OK) /* nothing */; deflateEnd(&stream); + free(unpacked); objsize = stream.total_out; } @@ -1348,6 +1352,12 @@ int write_sha1_to_fd(int fd, const unsig } posn += size; } while (posn < objsize); + + if (map) + munmap(map, objsize); + if (temp_obj) + free(temp_obj); + return 0; }
[PATCH 3/4] Plug memory leak in sha1close()
[PATCH] Plug memory leak in sha1close()
sha1create() and sha1fd() malloc the returned struct sha1file; sha1close() should free it.
Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> ---
csum-file.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
2207ae4977cbaa84636487ca24bad9d1116f54e0
diff --git a/csum-file.c b/csum-file.c --- a/csum-file.c +++ b/csum-file.c @@ -45,6 +45,7 @@ int sha1close(struct sha1file *f, unsign sha1flush(f, 20); if (close(f->fd)) die("%s: sha1 file error on close (%s)", f->name, strerror(errno)); + free(f); return 0; }
[PATCH 4/4] Plug memory leak in git-pack-objects
[PATCH] Plug memory leak in git-pack-objects
find_deltas() should free its temporary objects before returning.
Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> ---
pack-objects.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
8b38f80b97affd0d9808b8f276a9e2e04bf03464
diff --git a/pack-objects.c b/pack-objects.c --- a/pack-objects.c +++ b/pack-objects.c @@ -382,6 +382,10 @@ static void find_deltas(struct object_en if (idx >= window) idx = 0; } + + for (i = 0; i < window; ++i) + free(array[i].data); + free(array); } int main(int argc, char **argv)