shithub: riscv

Download patch

ref: 105ebc327abe965cf11242e6c300d28979938f5e
parent: 21cedbedb24c2af04ac3b141ff6ce112c5d6e582
author: cinap_lenrek <[email protected]>
date: Sat Jan 28 22:21:09 EST 2012

sam: fix memory leak for name in fwrite

--- a/sys/src/cmd/sam/io.c
+++ b/sys/src/cmd/sam/io.c
@@ -41,6 +41,7 @@
 		f->qidpath = qid;
 		f->mtime = mtime;
 		warn_S(Wdate, &genstr);
+		free(name);
 		return;
 	}
 	if(genc)
@@ -49,8 +50,10 @@
 	if((io=create(genc, 1, 0666L)) < 0)
 		error_r(Ecreate, genc);
 	dprint("%s: ", genc);
-	if(statfd(io, 0, 0, 0, &length, &appendonly) > 0 && appendonly && length>0)
+	if(statfd(io, 0, 0, 0, &length, &appendonly) > 0 && appendonly && length>0){
+		free(name);
 		error(Eappend);
+	}
 	n = writeio(f);
 	if(f->name.s[0]==0 || samename){
 		if(addr.r.p1==0 && addr.r.p2==f->nc)
@@ -70,6 +73,7 @@
 			checkqid(f);
 		}
 	}
+	free(name);
 }
 
 Posn