From 705a2c3c28d61447487abd48b3db58450f8e70e0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 7 Jan 2025 06:49:40 +0000 Subject: [PATCH] netif: fix potential memory leak in netifwstat() convM2D() might fault and raise error, leaking sizeof(Dir)+n allocation. --- sys/src/9/port/netif.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sys/src/9/port/netif.c b/sys/src/9/port/netif.c index 42a3b3ccc..0239fa201 100644 --- a/sys/src/9/port/netif.c +++ b/sys/src/9/port/netif.c @@ -418,11 +418,13 @@ netifwstat(Netif *nif, Chan *c, uchar *db, int n) 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 @@ netifwstat(Netif *nif, Chan *c, uchar *db, int n) if(dir[0].mode != ~0UL) f->mode = dir[0].mode; free(dir); + poperror(); return m; }