shithub: front

Download patch

ref: 705a2c3c28d61447487abd48b3db58450f8e70e0
parent: 00c25292d7e3fa8bd5a6fdd2bd95aa164ae27469
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jan 7 01:49:40 EST 2025

netif: fix potential memory leak in netifwstat()

convM2D() might fault and raise error, leaking
sizeof(Dir)+n allocation.

--- a/sys/src/9/port/netif.c
+++ b/sys/src/9/port/netif.c
@@ -418,11 +418,13 @@
 		error(Eperm);
 
 	dir = smalloc(sizeof(Dir)+n);
-	m = convM2D(db, n, &dir[0], (char*)&dir[1]);
-	if(m == 0){
+	if(waserror()){
 		free(dir);
-		error(Eshortstat);
+		nexterror();
 	}
+	m = convM2D(db, n, &dir[0], (char*)&dir[1]);
+	if(m == 0)
+		error(Eshortstat);
 	if(!emptystr(dir[0].uid)){
 		strncpy(f->owner, dir[0].uid, KNAMELEN-1);
 		f->owner[KNAMELEN-1] = 0;
@@ -430,6 +432,7 @@
 	if(dir[0].mode != ~0UL)
 		f->mode = dir[0].mode;
 	free(dir);
+	poperror();
 	return m;
 }
 
--