lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7chQQK2DP_gEFdi-OG5X6wCoouH75Jsg-V=UEFpuB-5bFA@mail.gmail.com>
Date:   Mon, 7 Dec 2020 22:20:25 +0900
From:   Namhyung Kim <namhyung@...nel.org>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...hat.com>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        Andi Kleen <ak@...ux.intel.com>,
        Jin Yao <yao.jin@...ux.intel.com>,
        John Garry <john.garry@...wei.com>,
        Paul Clarke <pc@...ibm.com>, kajoljain <kjain@...ux.ibm.com>,
        Stephane Eranian <eranian@...gle.com>,
        Sandeep Dasgupta <sdasgup@...gle.com>
Subject: Re: [PATCH v5 1/5] perf metric: Restructure struct expr_parse_ctx.

Hi Ian,

On Wed, Dec 2, 2020 at 4:40 PM Ian Rogers <irogers@...gle.com> wrote:
>
> A later change to parsing the ids out (in expr__find_other) will
> potentially drop hashmaps and so it is more convenient to move
> expr_parse_ctx to have a hashmap pointer rather than a struct value. As
> this pointer must be freed, rather than just going out of scope,
> add expr__ctx_new and expr__ctx_free to manage expr_parse_ctx memory.
> Adjust use of struct expr_parse_ctx accordingly.
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
[SNIP]
> -void expr__ctx_init(struct expr_parse_ctx *ctx)
> +struct expr_parse_ctx *expr__ctx_new(void)
>  {
> -       hashmap__init(&ctx->ids, key_hash, key_equal, NULL);
> +       struct expr_parse_ctx *ctx;
> +
> +       ctx = malloc(sizeof(struct expr_parse_ctx));
> +       if (!ctx)
> +               return NULL;
> +
> +       ctx->ids = hashmap__new(key_hash, key_equal, NULL);
> +       ctx->parent = NULL;
> +       return ctx;
>  }
>
>  void expr__ctx_clear(struct expr_parse_ctx *ctx)
> @@ -221,11 +229,23 @@ void expr__ctx_clear(struct expr_parse_ctx *ctx)
>         struct hashmap_entry *cur;
>         size_t bkt;
>
> -       hashmap__for_each_entry((&ctx->ids), cur, bkt) {
> +       hashmap__for_each_entry(ctx->ids, cur, bkt) {
> +               free((char *)cur->key);
> +               free(cur->value);
> +       }
> +       hashmap__clear(ctx->ids);
> +}
> +
> +void expr__ctx_free(struct expr_parse_ctx *ctx)
> +{
> +       struct hashmap_entry *cur;
> +       size_t bkt;
> +
> +       hashmap__for_each_entry(ctx->ids, cur, bkt) {
>                 free((char *)cur->key);
>                 free(cur->value);
>         }
> -       hashmap__clear(&ctx->ids);
> +       hashmap__free(ctx->ids);
>  }

I think this function should free the ctx itself.

Thanks,
Namhyung

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ