From b3d47c3a3ae1d2367a68ad0f56204f603a2ffc4c Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Mon, 14 May 2012 01:35:17 +0200 Subject: [PATCH] libplumb: realloc memleak (thank you clsmith, THANK YOU!) --- sys/src/libplumb/mesg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sys/src/libplumb/mesg.c b/sys/src/libplumb/mesg.c index 455d8ca1b..7b4c090fb 100644 --- a/sys/src/libplumb/mesg.c +++ b/sys/src/libplumb/mesg.c @@ -411,7 +411,7 @@ plumbunpack(char *buf, int n) Plumbmsg* plumbrecv(int fd) { - char *buf; + char *buf, *old; Plumbmsg *m; int n, more; @@ -424,9 +424,11 @@ plumbrecv(int fd) m = plumbunpackpartial(buf, n, &more); if(m==nil && more>0){ /* we now know how many more bytes to read for complete message */ - buf = realloc(buf, n+more); - if(buf == nil) + buf = realloc(old = buf, n+more); + if(buf == nil){ + free(old); return nil; + } if(readn(fd, buf+n, more) == more) m = plumbunpackpartial(buf, n+more, nil); }