Skip to contentSkip to conversation

elf2dmp: free memory in failure

PATCH RESEND Applied luzhipeng 3 participants 3 messages Oct 7, 2022 – Oct 22, 2022

lore
Share & tools
lore

luzhipeng

author
#0 lore raw

PATCH RESEND 1/1 elf2dmp: free memory in failure

From: lu zhipeng <[email protected]>

The 'kdgb' is allocating memory in get_kdbg(), but it is not freed in error path. So fix that.

---
 contrib/elf2dmp/main.c | 1 +
 1 file changed, 1 insertion(+)
contrib/elf2dmp/main.c +1 -0
index b9fc6d230c..d77b8f98f7 100644
@@ -125,6 +125,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb,
 
     if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) {
         eprintf("Failed to extract entire KDBG\n");
+        free(kdbg);
         return NULL;
     }
 
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · luzhipeng

From: lu zhipeng <[email protected]>

The 'kdgb' is allocating memory in get_kdbg(), but it is not freed in error path. So fix that.

---
  contrib/elf2dmp/main.c | 1 +
  1 file changed, 1 insertion(+)
contrib/elf2dmp/main.c +0 -0
index b9fc6d230c..d77b8f98f7 100644

contrib/elf2dmp/main.c static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, · line 131

Quoted 7 lines
contrib/elf2dmp/main.c +1 -0
@@ -125,6 +125,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb,
 
      if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) {
          eprintf("Failed to extract entire KDBG\n");
+        free(kdbg);
          return NULL;
      }
 

I suppose Philippe's R-b should be on this version of the patch, not previous one. Also I'm not sure if this patch should go through Paolo's branch or QEMU Trivial.

#2 lore raw
In reply to luzhipeng

Le 07/10/2022 à 04:01, luzhipeng a écrit :

Quoted 15 lines

From: lu zhipeng <[email protected]>

The 'kdgb' is allocating memory in get_kdbg(), but it is not freed in error path. So fix that.

---
  contrib/elf2dmp/main.c | 1 +
  1 file changed, 1 insertion(+)
contrib/elf2dmp/main.c +0 -0
index b9fc6d230c..d77b8f98f7 100644

contrib/elf2dmp/main.c static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, · line 131

Quoted 7 lines
contrib/elf2dmp/main.c +1 -0
@@ -125,6 +125,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb,
 
      if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) {
          eprintf("Failed to extract entire KDBG\n");
+        free(kdbg);
          return NULL;
      }
 

Applied to my trivial-patches branch.

Thanks,
Laurent