git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Plug some more memory leaks in git
@ 2005-08-08 18:43 Sergey Vlasov
  2005-08-08 18:44 ` [PATCH 1/4] Plug memory leak in read_object_with_reference() Sergey Vlasov
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sergey Vlasov @ 2005-08-08 18:43 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] Plug memory leak in read_object_with_reference()
  2005-08-08 18:43 [PATCH 0/4] Plug some more memory leaks in git Sergey Vlasov
@ 2005-08-08 18:44 ` Sergey Vlasov
  2005-08-08 18:45 ` [PATCH 2/4] Plug memory leak in write_sha1_to_fd() Sergey Vlasov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Vlasov @ 2005-08-08 18:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[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. */
 	}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] Plug memory leak in write_sha1_to_fd()
  2005-08-08 18:43 [PATCH 0/4] Plug some more memory leaks in git Sergey Vlasov
  2005-08-08 18:44 ` [PATCH 1/4] Plug memory leak in read_object_with_reference() Sergey Vlasov
@ 2005-08-08 18:45 ` Sergey Vlasov
  2005-08-08 18:46 ` [PATCH 3/4] Plug memory leak in sha1close() Sergey Vlasov
  2005-08-08 18:46 ` [PATCH 4/4] Plug memory leak in git-pack-objects Sergey Vlasov
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Vlasov @ 2005-08-08 18:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[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;
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] Plug memory leak in sha1close()
  2005-08-08 18:43 [PATCH 0/4] Plug some more memory leaks in git Sergey Vlasov
  2005-08-08 18:44 ` [PATCH 1/4] Plug memory leak in read_object_with_reference() Sergey Vlasov
  2005-08-08 18:45 ` [PATCH 2/4] Plug memory leak in write_sha1_to_fd() Sergey Vlasov
@ 2005-08-08 18:46 ` Sergey Vlasov
  2005-08-08 18:46 ` [PATCH 4/4] Plug memory leak in git-pack-objects Sergey Vlasov
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Vlasov @ 2005-08-08 18:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[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;
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] Plug memory leak in git-pack-objects
  2005-08-08 18:43 [PATCH 0/4] Plug some more memory leaks in git Sergey Vlasov
                   ` (2 preceding siblings ...)
  2005-08-08 18:46 ` [PATCH 3/4] Plug memory leak in sha1close() Sergey Vlasov
@ 2005-08-08 18:46 ` Sergey Vlasov
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Vlasov @ 2005-08-08 18:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

[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)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-08-08 18:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-08 18:43 [PATCH 0/4] Plug some more memory leaks in git Sergey Vlasov
2005-08-08 18:44 ` [PATCH 1/4] Plug memory leak in read_object_with_reference() Sergey Vlasov
2005-08-08 18:45 ` [PATCH 2/4] Plug memory leak in write_sha1_to_fd() Sergey Vlasov
2005-08-08 18:46 ` [PATCH 3/4] Plug memory leak in sha1close() Sergey Vlasov
2005-08-08 18:46 ` [PATCH 4/4] Plug memory leak in git-pack-objects Sergey Vlasov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).