shithub: drawterm-fdroid

Download patch

ref: efbc81f6f60f7e0e25e6e7055873f1a30359b3b1
parent: 0757b2cd45e39cf86c9fa468864d993e6ac8211f
author: cinap_lenrek <[email protected]>
date: Thu Dec 8 19:12:43 EST 2016

devfs-*.c: fix memory leak on remove, implement ORCLOSE

fsremove() is supposed to clunk the channel, even
on error, freeing the resouces associated with the
Chan.aux pointer.

handle ORCLOSE in fsclose().

--- a/kern/devfs-posix.c
+++ b/kern/devfs-posix.c
@@ -288,6 +288,11 @@
 			closedir(uif->dir);
 		else
 			close(uif->fd);
+		c->flag &= ~COPEN;
+		if(c->flag & CRCLOSE) {
+			devtab[c->type]->remove(c);
+			return;
+		}
 	}
 	free(uif->path);
 	free(uif);
@@ -365,6 +370,10 @@
 	int n;
 	Ufsinfo *uif;
 
+	if(waserror()){
+		fsclose(c);
+		nexterror();
+	}
 	uif = c->aux;
 	if(c->qid.type & QTDIR)
 		n = rmdir(uif->path);
@@ -372,6 +381,8 @@
 		n = remove(uif->path);
 	if(n < 0)
 		error(strerror(errno));
+	poperror();
+	fsclose(c);
 }
 
 int
--- a/kern/devfs-win32.c
+++ b/kern/devfs-win32.c
@@ -466,6 +466,11 @@
 		} else {
 			CloseHandle(uif->fh);
 		}
+		c->flag &= ~COPEN;
+		if(c->flag & CRCLOSE) {
+			devtab[c->type]->remove(c);
+			return;
+		}
 	}
 	free(uif->path);
 	free(uif);
@@ -544,6 +549,10 @@
 {
 	Ufsinfo *uif;
 
+	if(waserror()){
+		fsclose(c);
+		nexterror();
+	}
 	uif = c->aux;
 	if(c->qid.type & QTDIR){
 		if(!RemoveDirectory(uif->path))
@@ -552,6 +561,8 @@
 		if(!DeleteFile(uif->path))
 			oserror();
 	}
+	poperror();
+	fsclose(c);
 }
 
 static int