git » libjio » commit da4662c

There was a very strange and weird bug inside jfsck() which can lead to SIGSEGV inside malloc(), for instance. In the end it was just a very weird corner case of a buffer being misfreed. This patch moves the free() where it belongs.

author Alberto Bertogli
2004-04-05 15:35:08 UTC
committer Alberto Bertogli
2007-07-15 12:31:26 UTC
parent fcc11deb608f7a751f22a7ebab8ace9cc1f850f4

There was a very strange and weird bug inside jfsck() which can lead to SIGSEGV inside malloc(), for instance. In the end it was just a very weird corner case of a buffer being misfreed. This patch moves the free() where it belongs.

There was a very strange and weird bug inside jfsck() which can lead to
SIGSEGV inside malloc(), for instance. In the end it was just a very weird
corner case of a buffer being misfreed. This patch moves the free() where it
belongs.

libjio.c +4 -2

diff --git a/libjio.c b/libjio.c
index 663118a..f245e84 100644
--- a/libjio.c
+++ b/libjio.c
@@ -777,6 +777,7 @@ int jfsck(char *name, struct jfsck_result *res)
 		rv = read(tfd, buf, J_DISKTFIXSIZE);
 		if (rv != J_DISKTFIXSIZE) {
 			res->broken_head++;
+			free(buf);
 			goto loop;
 		}
 		
@@ -785,6 +786,8 @@ int jfsck(char *name, struct jfsck_result *res)
 		curts->ulen = (size_t) *(buf + 16);
 		curts->offset = (off_t) *(buf + 20);
 
+		free(buf);
+
 		/* if we got here, the transaction was not applied, so we
 		 * check if the transaction file is complete (we only need to
 		 * apply it) or not (so we can't do anything but ignore it) */
@@ -872,8 +875,7 @@ int jfsck(char *name, struct jfsck_result *res)
 loop:
 		if (tfd > 0)
 			close(tfd);
-		if (buf)
-			free(buf);
+
 		free(curts);
 
 		res->total++;