diff mbox series

elf2dmp: Fix memory leak on main() error paths

Message ID 5F463659.8080101@huawei.com
State Superseded
Headers show
Series elf2dmp: Fix memory leak on main() error paths | expand

Commit Message

Alex Chen Aug. 26, 2020, 10:15 a.m. UTC
From: AlexChen <alex.chen@huawei.com>

The 'kdgb' is allocating memory in get_kdbg(), but it is not freed
in both fill_header() and fill_context() failed branches, fix it.

Signed-off-by: AlexChen <alex.chen@huawei.com>
---
 contrib/elf2dmp/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Viktor Prutyanov Sept. 10, 2020, 8:33 p.m. UTC | #1
On Wed, 26 Aug 2020 18:15:53 +0800
AlexChen <alex.chen@huawei.com> wrote:

> From: AlexChen <alex.chen@huawei.com>
> 
> The 'kdgb' is allocating memory in get_kdbg(), but it is not freed
> in both fill_header() and fill_context() failed branches, fix it.
> 
> Signed-off-by: AlexChen <alex.chen@huawei.com>
> ---
>  contrib/elf2dmp/main.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
> index 9a2dbc2902..ac746e49e0 100644
> --- a/contrib/elf2dmp/main.c
> +++ b/contrib/elf2dmp/main.c
> @@ -568,12 +568,12 @@ int main(int argc, char *argv[])
>      if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg,
>              KdVersionBlock, qemu_elf.state_nr)) {
>          err = 1;
> -        goto out_pdb;
> +        goto out_kdbg;
>      }
> 
>      if (fill_context(kdbg, &vs, &qemu_elf)) {
>          err = 1;
> -        goto out_pdb;
> +        goto out_kdbg;
>      }
> 
>      if (write_dump(&ps, &header, argv[2])) {

Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu>
Laurent Vivier Sept. 11, 2020, 7:01 a.m. UTC | #2
Le 11/09/2020 à 06:18, Thomas Huth a écrit :
> On 26/08/2020 12.15, AlexChen wrote:
>> From: AlexChen <alex.chen@huawei.com>
>>
>> The 'kdgb' is allocating memory in get_kdbg(), but it is not freed
>> in both fill_header() and fill_context() failed branches, fix it.
>>
>> Signed-off-by: AlexChen <alex.chen@huawei.com>
>> ---
>>  contrib/elf2dmp/main.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c
>> index 9a2dbc2902..ac746e49e0 100644
>> --- a/contrib/elf2dmp/main.c
>> +++ b/contrib/elf2dmp/main.c
>> @@ -568,12 +568,12 @@ int main(int argc, char *argv[])
>>      if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg,
>>              KdVersionBlock, qemu_elf.state_nr)) {
>>          err = 1;
>> -        goto out_pdb;
>> +        goto out_kdbg;
>>      }
>>
>>      if (fill_context(kdbg, &vs, &qemu_elf)) {
>>          err = 1;
>> -        goto out_pdb;
>> +        goto out_kdbg;
>>      }
>>
>>      if (write_dump(&ps, &header, argv[2])) {
>>
> 
> I think this could go via qemu-trivial (now on CC:).
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> 
> 

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 9a2dbc2902..ac746e49e0 100644
--- a/contrib/elf2dmp/main.c
+++ b/contrib/elf2dmp/main.c
@@ -568,12 +568,12 @@  int main(int argc, char *argv[])
     if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg,
             KdVersionBlock, qemu_elf.state_nr)) {
         err = 1;
-        goto out_pdb;
+        goto out_kdbg;
     }

     if (fill_context(kdbg, &vs, &qemu_elf)) {
         err = 1;
-        goto out_pdb;
+        goto out_kdbg;
     }

     if (write_dump(&ps, &header, argv[2])) {