diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-05-14 01:35:17 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-05-14 01:35:17 +0200 |
commit | b3d47c3a3ae1d2367a68ad0f56204f603a2ffc4c (patch) | |
tree | 5370212c821baf7745895b7ae097b3572895e6df /sys/src/libplumb | |
parent | 042bc5be352d06950e780705d2384ddeb964d232 (diff) |
libplumb: realloc memleak (thank you clsmith, THANK YOU!)
Diffstat (limited to 'sys/src/libplumb')
-rw-r--r-- | sys/src/libplumb/mesg.c | 8 |
1 files 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); } |