tlibmach: plug memory leak - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 2c97de1a26686adf2a6377bc4ef18d1aec6a1f3a
 (DIR) parent a4e59b37021326e304c311825ba52a52b02bd9c0
 (HTM) Author: Neven Sajko <nsajko@gmail.com>
       Date:   Sun, 11 Aug 2019 00:54:13 +0000
       
       libmach: plug memory leak
       
       Change-Id: I08cb7227c071c7fc2e30f43e07bcf599fc1d174a
       
       Diffstat:
         M src/libmach/elf.c                   |       5 ++++-
       
       1 file changed, 4 insertions(+), 1 deletion(-)
       ---
 (DIR) diff --git a/src/libmach/elf.c b/src/libmach/elf.c
       t@@ -191,7 +191,7 @@ elfinit(int fd)
                        ElfHdrBytes h32;
                        ElfHdrBytes64 h64;
                } hdrb;
       -        void *p;
       +        void *p = nil;
                ElfSect *s;
        
                e = mallocz(sizeof(Elf), 1);
       t@@ -234,6 +234,7 @@ elfinit(int fd)
                        unpackprog(h, &e->prog[i], p);
                }
                free(p);
       +        p = nil;
        
                e->nsect = h->shnum;
                if(e->nsect == 0)
       t@@ -247,6 +248,7 @@ elfinit(int fd)
                        unpacksect(h, &e->sect[i], p);
                }
                free(p);
       +        p = nil;
        
                if(h->shstrndx >= e->nsect){
                        fprint(2, "warning: bad string section index %d >= %d", h->shstrndx, e->nsect);
       t@@ -287,6 +289,7 @@ nosects:
                return e;
        
        err:
       +        free(p);
                free(e->sect);
                free(e->prog);
                free(e->shstrtab);