shithub: 9pro

Download patch

ref: dc8c3343ee6a06343bc75f58c693d86f924d66a7
parent: 99cc37a021706ce117745d6e8fe950f9f40c24d8
author: Sigrid Haflínudóttir <[email protected]>
date: Tue Jan 7 17:53:15 EST 2020

fix a memory leak

--- a/9pex.c
+++ b/9pex.c
@@ -642,7 +642,7 @@
 	ssize_t n;
 	C9stat c9st[16], *c9stp[16];
 	long dirpos[16];
-	int i, num;
+	int i, num, res;
 
 	if (size > c->msize - 12) /* make sure it fits */
 		size = c->msize - 12;
@@ -654,9 +654,12 @@
 		}
 		if ((n = pread(f->fd, p, size, offset)) < 0) {
 			*err = strerror(errno);
+			free(p);
 			return -1;
 		}
-		if (s9do(s9read(c, tag, p, n), err) != 0)
+		res = s9do(s9read(c, tag, p, n), err);
+		free(p);
+		if (res != 0)
 			return -1;
 		trace("<- Rread tag=%d count=%zd data=...\n", tag, n);
 		return 0;