[dm-devel] [PATCH] remove unuseful MALLOC/REALLOC/STRDUP/FREE

Martin Wilck mwilck at suse.com
Fri Nov 26 16:14:32 UTC 2021


On Fri, 2021-11-26 at 16:37 +0800, lixiaokeng wrote:
> Now there are tools such as valgrind and asan to detect memory leaks,
> so it is unnecessary to use _DEBUG_. Remove _DEBUG_ code.
> 
> Signed-off-by: Lixiaokeng<lixiaokeng at huawei.com>
> ---
>  libmpathpersist/mpath_persist.c          |   4 +-
>  libmpathpersist/mpath_updatepr.c         |   1 -
>  libmultipath/Makefile                    |   2 +-
>  libmultipath/alias.c                     |   2 +-
>  libmultipath/blacklist.c                 |  27 +-
>  libmultipath/checkers.c                  |   4 +-
>  libmultipath/checkers.h                  |   4 +-
>  libmultipath/checkers/emc_clariion.c     |   3 +-
>  libmultipath/config.c                    |  85 +++--
>  libmultipath/configure.c                 |  21 +-
>  libmultipath/defaults.c                  |   1 -
>  libmultipath/defaults.h                  |   1 +
>  libmultipath/devmapper.c                 |  15 +-
>  libmultipath/dict.c                      |  49 ++-
>  libmultipath/discovery.c                 |   1 -
>  libmultipath/dmparser.c                  |  47 ++-
>  libmultipath/io_err_stat.c               |  13 +-
>  libmultipath/log.c                       |  22 +-
>  libmultipath/log_pthread.c               |   2 -
>  libmultipath/memory.c                    | 444 ---------------------
> --
>  libmultipath/memory.h                    |  66 ----
>  libmultipath/parser.c                    |  25 +-
>  libmultipath/pgpolicies.c                |   5 +-
>  libmultipath/prio.c                      |   4 +-
>  libmultipath/prio.h                      |   1 -
>  libmultipath/prioritizers/path_latency.c |   6 +-
>  libmultipath/prioritizers/weightedpath.c |   1 -
>  libmultipath/propsel.c                   |  11 +-
>  libmultipath/structs.c                   |  51 ++-
>  libmultipath/sysfs.c                     |   2 +-
>  libmultipath/uevent.c                    |  13 +-
>  libmultipath/util.c                      |   7 +-
>  libmultipath/util.h                      |   1 +
>  libmultipath/uxsock.c                    |   5 +-
>  libmultipath/vector.c                    |  15 +-
>  multipath/main.c                         |  19 +-
>  multipathd/cli.c                         |  23 +-
>  multipathd/cli.h                         |   2 +-
>  multipathd/cli_handlers.c                |   7 +-
>  multipathd/main.c                        |  33 +-
>  multipathd/uxclnt.c                      |   5 +-
>  multipathd/uxlsnr.c                      |  17 +-
>  multipathd/waiter.c                      |   5 +-
>  tests/pgpolicy.c                         |   1 +
>  tests/uevent.c                           |   8 +-
>  45 files changed, 268 insertions(+), 813 deletions(-)
>  delete mode 100644 libmultipath/memory.c
>  delete mode 100644 libmultipath/memory.h
> 
> 

Nice work! I only found one minor glitch, see below.

I'd have been even happier if this had been based on Ben's and my
recent work, but no problem; I'll rebase the other patches, as I need
to  re-send them anyway.


> diff --git a/multipathd/main.c b/multipathd/main.c
> index 1defeaf1..ea2af833 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
>                 r = 0;
> @@ -2800,7 +2799,7 @@ init_vecs (void)
>  {
>         struct vectors * vecs;
> 
> -       vecs = (struct vectors *)MALLOC(sizeof(struct vectors));
> +       vecs = (struct vectors *)calloc(1, sizeof(struct vectors));
> 
>         if (!vecs)
>                 return NULL;
> @@ -3012,7 +3011,7 @@ static void cleanup_vecs(void)
>         cleanup_maps(gvecs);
>         cleanup_paths(gvecs);
>         pthread_mutex_destroy(&gvecs->lock.mutex);
> -       FREE(gvecs);
> +       free(gvecs);
>  }

I'd feel better if we set gvecs = NULL here. It's not strictly
necessary because we're in cleanup, but if we mess up something
in the cleanup code path in the future, diagnosing that will be easier.

If you don't mind, I'll just add that statement here.

Thanks,
Martin






More information about the dm-devel mailing list