diff mbox series

[RESEND] elf2dmp: free memory in failure

Message ID 20221007020128.760-1-luzhipeng@cestc.cn (mailing list archive)
State New, archived
Headers show
Series [RESEND] elf2dmp: free memory in failure | expand

Commit Message

Zhipeng Lu Oct. 7, 2022, 2:01 a.m. UTC
From: lu zhipeng <luzhipeng@cestc.cn>

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

Signed-off-by: lu zhipeng <luzhipeng@cestc.cn>
---
 contrib/elf2dmp/main.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Viktor Prutyanov Oct. 21, 2022, 2:02 a.m. UTC | #1
On 10/7/22 5:01 AM, luzhipeng wrote:
> From: lu zhipeng <luzhipeng@cestc.cn>
> 
> The 'kdgb' is allocating memory in get_kdbg(), but it is not freed in
> error path. So fix that.
> 
> Signed-off-by: lu zhipeng <luzhipeng@cestc.cn>
> ---
>   contrib/elf2dmp/main.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
> index b9fc6d230c..d77b8f98f7 100644
> --- a/contrib/elf2dmp/main.c
> +++ b/contrib/elf2dmp/main.c
> @@ -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.

Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Laurent Vivier Oct. 22, 2022, 9:11 p.m. UTC | #2
Le 07/10/2022 à 04:01, luzhipeng a écrit :
> From: lu zhipeng <luzhipeng@cestc.cn>
> 
> The 'kdgb' is allocating memory in get_kdbg(), but it is not freed in
> error path. So fix that.
> 
> Signed-off-by: lu zhipeng <luzhipeng@cestc.cn>
> ---
>   contrib/elf2dmp/main.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
> index b9fc6d230c..d77b8f98f7 100644
> --- a/contrib/elf2dmp/main.c
> +++ b/contrib/elf2dmp/main.c
> @@ -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
diff mbox series

Patch

diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
index b9fc6d230c..d77b8f98f7 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -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;
     }