All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] cov: fix memory leak caused by abnormal exit
@ 2021-08-30  7:12 Wu Guanghao
  2021-08-30  7:13 ` [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed Wu Guanghao
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Wu Guanghao @ 2021-08-30  7:12 UTC (permalink / raw)
  To: lvm-devel

Several possible memory leaks were discovered through tool scans

wuguanghao (3):
  cmdlib_lvm2_init: release cmd after registration failed
  read_adopt_file: Set the default value of r to NULL,
        and release r when exiting abnormally
  read_adopt_file: fix memory leak

 daemons/lvmlockd/lvmlockd-core.c | 7 +++++--
 tools/lvmcmdlib.c                | 4 +++-
 2 files changed, 8 insertions(+), 3 deletions(-)

--
2.23.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed
  2021-08-30  7:12 [PATCH 0/3] cov: fix memory leak caused by abnormal exit Wu Guanghao
@ 2021-08-30  7:13 ` Wu Guanghao
  2021-09-10 15:00   ` Zdenek Kabelac
  2021-08-30  7:13 ` [PATCH 2/3] read_adopt_file: release r when exiting abnormally Wu Guanghao
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Wu Guanghao @ 2021-08-30  7:13 UTC (permalink / raw)
  To: lvm-devel

The cmd memory space is allocated by zalloc, and the registration fails and is not released

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 tools/lvmcmdlib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/lvmcmdlib.c b/tools/lvmcmdlib.c
index 152d176b2..6b326893c 100644
--- a/tools/lvmcmdlib.c
+++ b/tools/lvmcmdlib.c
@@ -33,8 +33,10 @@ void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded)
        if (!(cmd = init_lvm(1, 1, threaded)))
                return NULL;

-       if (!lvm_register_commands(cmd, NULL))
+       if (!lvm_register_commands(cmd, NULL)) {
+               free(cmd);
                return NULL;
+       }

        return (void *) cmd;
 }
--
2.23.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] read_adopt_file: release r when exiting abnormally
  2021-08-30  7:12 [PATCH 0/3] cov: fix memory leak caused by abnormal exit Wu Guanghao
  2021-08-30  7:13 ` [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed Wu Guanghao
@ 2021-08-30  7:13 ` Wu Guanghao
  2021-08-30  7:14 ` [PATCH 3/3] read_adopt_file: fix memory leak Wu Guanghao
  2021-09-10  2:21 ` [PATCH 0/3] cov: fix memory leak caused by abnormal exit Zhiqiang Liu
  3 siblings, 0 replies; 7+ messages in thread
From: Wu Guanghao @ 2021-08-30  7:13 UTC (permalink / raw)
  To: lvm-devel

When exiting abnormally, r may not be released.At the same time, avoid freeing up other space,
set the default value of r to NULL

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 daemons/lvmlockd/lvmlockd-core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index fef9589b9..d4d7f106f 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -938,7 +938,7 @@ static int read_adopt_file(struct list_head *vg_lockd)
        char lm_type_str[16];
        char mode[8];
        struct lockspace *ls = NULL, *ls2;
-       struct resource *r;
+       struct resource *r = NULL;
        FILE *fp;

        if (MAX_ARGS != 64 || MAX_NAME != 64)
@@ -1012,6 +1012,7 @@ static int read_adopt_file(struct list_head *vg_lockd)
                }
        }

+       free_resource(r);
        fclose(fp);
        return 0;

--
2.23.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] read_adopt_file: fix memory leak
  2021-08-30  7:12 [PATCH 0/3] cov: fix memory leak caused by abnormal exit Wu Guanghao
  2021-08-30  7:13 ` [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed Wu Guanghao
  2021-08-30  7:13 ` [PATCH 2/3] read_adopt_file: release r when exiting abnormally Wu Guanghao
@ 2021-08-30  7:14 ` Wu Guanghao
  2021-09-10  2:21 ` [PATCH 0/3] cov: fix memory leak caused by abnormal exit Zhiqiang Liu
  3 siblings, 0 replies; 7+ messages in thread
From: Wu Guanghao @ 2021-08-30  7:14 UTC (permalink / raw)
  To: lvm-devel

When exiting abnormally, forget to release ls

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
 daemons/lvmlockd/lvmlockd-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
index d4d7f106f..71d708603 100644
--- a/daemons/lvmlockd/lvmlockd-core.c
+++ b/daemons/lvmlockd/lvmlockd-core.c
@@ -970,8 +970,10 @@ static int read_adopt_file(struct list_head *vg_lockd)

                        memcpy(ls->vg_uuid, vg_uuid, 64);

-                       if ((ls->lm_type = str_to_lm(lm_type_str)) < 0)
+                       if ((ls->lm_type = str_to_lm(lm_type_str)) < 0) {
+                               free(ls);
                                goto fail;
+                       }

                        list_add(&ls->list, vg_lockd);

--
2.23.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 0/3] cov: fix memory leak caused by abnormal exit
  2021-08-30  7:12 [PATCH 0/3] cov: fix memory leak caused by abnormal exit Wu Guanghao
                   ` (2 preceding siblings ...)
  2021-08-30  7:14 ` [PATCH 3/3] read_adopt_file: fix memory leak Wu Guanghao
@ 2021-09-10  2:21 ` Zhiqiang Liu
  2021-09-10 13:11   ` David Teigland
  3 siblings, 1 reply; 7+ messages in thread
From: Zhiqiang Liu @ 2021-09-10  2:21 UTC (permalink / raw)
  To: lvm-devel

ping...

On 2021/8/30 15:12, Wu Guanghao wrote:
> Several possible memory leaks were discovered through tool scans
>
> wuguanghao (3):
>   cmdlib_lvm2_init: release cmd after registration failed
>   read_adopt_file: Set the default value of r to NULL,
>         and release r when exiting abnormally
>   read_adopt_file: fix memory leak
>
>  daemons/lvmlockd/lvmlockd-core.c | 7 +++++--
>  tools/lvmcmdlib.c                | 4 +++-
>  2 files changed, 8 insertions(+), 3 deletions(-)
>
> --
> 2.23.0
>
> .



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/3] cov: fix memory leak caused by abnormal exit
  2021-09-10  2:21 ` [PATCH 0/3] cov: fix memory leak caused by abnormal exit Zhiqiang Liu
@ 2021-09-10 13:11   ` David Teigland
  0 siblings, 0 replies; 7+ messages in thread
From: David Teigland @ 2021-09-10 13:11 UTC (permalink / raw)
  To: lvm-devel

On Fri, Sep 10, 2021 at 10:21:50AM +0800, Zhiqiang Liu wrote:
> ping...
> 
> On 2021/8/30 15:12, Wu Guanghao wrote:
> > Several possible memory leaks were discovered through tool scans
> >
> > wuguanghao (3):
> >   cmdlib_lvm2_init: release cmd after registration failed
> >   read_adopt_file: Set the default value of r to NULL,
> >         and release r when exiting abnormally
> >   read_adopt_file: fix memory leak

this commit addressed part of that, but the first didn't seem quite right.
https://sourceware.org/git/?p=lvm2.git;a=blobdiff;f=daemons/lvmlockd/lvmlockd-core.c;h=c570b9d14eb6ec0db4e0bffb371a3cd70c67d9b6;hp=fef9589b9d985e5767c19db2650235fbfd406f7f;hb=62c599f78151e65105c92c87ac406e3f3f360b1a;hpb=350f8845bd39dd7aaf5a52ad5deff6859fd06568



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed
  2021-08-30  7:13 ` [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed Wu Guanghao
@ 2021-09-10 15:00   ` Zdenek Kabelac
  0 siblings, 0 replies; 7+ messages in thread
From: Zdenek Kabelac @ 2021-09-10 15:00 UTC (permalink / raw)
  To: lvm-devel

Dne 30. 08. 21 v 9:13 Wu Guanghao napsal(a):
> The cmd memory space is allocated by zalloc, and the registration fails and is not released
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> ---
>   tools/lvmcmdlib.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lvmcmdlib.c b/tools/lvmcmdlib.c
> index 152d176b2..6b326893c 100644
> --- a/tools/lvmcmdlib.c
> +++ b/tools/lvmcmdlib.c
> @@ -33,8 +33,10 @@ void *cmdlib_lvm2_init(unsigned static_compile, unsigned threaded)
>          if (!(cmd = init_lvm(1, 1, threaded)))
>                  return NULL;
> 
> -       if (!lvm_register_commands(cmd, NULL))
> +       if (!lvm_register_commands(cmd, NULL)) {
> +               free(cmd);
>                  return NULL;
> +       }
> 
>          return (void *) cmd;


Well - all possible paths leading to 'return 0' from lvm_register_commands() 
are essentially  internal errors - so app should crash anyway,
but I guess it does no harm to add 'free()' call - so I'll push it.

Zdenek



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-10 15:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30  7:12 [PATCH 0/3] cov: fix memory leak caused by abnormal exit Wu Guanghao
2021-08-30  7:13 ` [PATCH 1/3] cmdlib_lvm2_init: release cmd after registration failed Wu Guanghao
2021-09-10 15:00   ` Zdenek Kabelac
2021-08-30  7:13 ` [PATCH 2/3] read_adopt_file: release r when exiting abnormally Wu Guanghao
2021-08-30  7:14 ` [PATCH 3/3] read_adopt_file: fix memory leak Wu Guanghao
2021-09-10  2:21 ` [PATCH 0/3] cov: fix memory leak caused by abnormal exit Zhiqiang Liu
2021-09-10 13:11   ` David Teigland

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.