]> git.lizzy.rs Git - plan9front.git/commitdiff
libplumb: realloc memleak (thank you clsmith, THANK YOU!)
authorcinap_lenrek <cinap_lenrek@gmx.de>
Sun, 13 May 2012 23:35:17 +0000 (01:35 +0200)
committercinap_lenrek <cinap_lenrek@gmx.de>
Sun, 13 May 2012 23:35:17 +0000 (01:35 +0200)
sys/src/libplumb/mesg.c

index 455d8ca1b5825ba2efdd2405c05fcffdbe828734..7b4c090fb95fa3ce942345f3d93910f698b55d63 100644 (file)
@@ -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);
                }