shithub: clone

Download patch

ref: 2f1d05541cf72a3cbedbbe0e8dc118ef62b3c2c7
parent: 99afac729632775756aae7679b4e91fb6c7f6fde
author: kvik <kvik@a-b.xyz>
date: Thu Nov 15 05:33:58 EST 2018

fix free of non-malloc'd pointer

--- a/clone.c
+++ b/clone.c
@@ -264,9 +264,11 @@
 void
 clone(char *src, char *dst)
 {
+	char *dn;
 	Dir *sd, *dd;
 	File *f;
 	
+	dn = estrdup(dst);
 	dd = nil;
 	sd = dirstat(src);
 	if(sd == nil){
@@ -273,14 +275,14 @@
 		error("can't stat: %r");
 		return;
 	}
-	if(access(dst, AEXIST) >= 0){
-		dd = dirstat(dst);
+	if(access(dn, AEXIST) >= 0){
+		dd = dirstat(dn);
 		if(dd == nil){
 			error("can't stat: %r");
 			goto End;
 		}
 	}else if(multisrc){
-		if(mkdir(src, dst, sd, &dd) < 0)
+		if(mkdir(src, dn, sd, &dd) < 0)
 			goto End;
 		skipdir = dd;
 	}
@@ -288,8 +290,8 @@
 	/* clone a file */
 	if(!(sd->mode & DMDIR)){
 		if(dd && dd->mode & DMDIR)
-			dst = smprint("%s/%s", dst, filename(src));
-		f = filenew(src, dst, sd);
+				dn = smprint("%s/%s", dn, filename(src));
+		f = filenew(src, dn, sd);
 		sendp(filechan, f);
 		goto End;
 	}
@@ -296,19 +298,20 @@
 
 	/* clone a directory */
 	if(dd)
-		dst = smprint("%s/%s", dst, filename(src));
+		dn = smprint("%s/%s", dn, filename(src));
 	if(skipdir){
-		if(mkdir(src, dst, sd, nil) < 0)
+		if(mkdir(src, dn, sd, nil) < 0)
 			goto End;
 	}else{
-		if(mkdir(src, dst, sd, &skipdir) < 0)
+		if(mkdir(src, dn, sd, &skipdir) < 0)
 			goto End;
 	}
-	clonedir(src, dst);
+	clonedir(src, dn);
 
 End:
-	if(dd) free(dst);
-	free(sd); free(dd);
+	free(dn);
+	free(sd);
+	free(dd);
 }
 
 void
@@ -422,6 +425,8 @@
 	char *buf;
 	File *f;
 	Blk *b;
+	
+	threadsetname("blkproc");
 
 	buf = emalloc(blksz);
 	for(;;){
@@ -451,6 +456,8 @@
 {
 	File *f;
 	WaitGroup *wg;
+	
+	threadsetname("fileproc");
 	
 	wg = v;
 	for(;;){