From 2c270e796ecc82567f5533bf1da35100b6eb4ee3 Mon Sep 17 00:00:00 2001 From: Evgeny Kolesnikov Date: Mon, 7 Sep 2020 08:03:38 +0200 Subject: [PATCH] Fix memory leak It seems that `SEXP_listref_first` result is not a good candidate to be (re)placed into a list. --- src/OVAL/probes/probe-api.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/OVAL/probes/probe-api.c b/src/OVAL/probes/probe-api.c index 3bae38ebc..417138c3b 100644 --- a/src/OVAL/probes/probe-api.c +++ b/src/OVAL/probes/probe-api.c @@ -130,6 +130,11 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val) { SEXP_t *n_ref, *ns; + if (val == NULL) + ns = SEXP_string_new(name, strlen(name)); + else + ns = SEXP_string_newf(":%s", name); + n_ref = SEXP_listref_first(item); if (SEXP_listp(n_ref)) { @@ -137,13 +142,7 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val) * There are already some attributes. * Just add the new to the list. */ - if (val == NULL) - ns = SEXP_string_new(name, strlen(name)); - else - ns = SEXP_string_newf(":%s", name); - SEXP_list_add(n_ref, ns); - SEXP_free(ns); if (val != NULL) SEXP_list_add(n_ref, val); @@ -155,23 +154,21 @@ SEXP_t *probe_item_attr_add(SEXP_t * item, const char *name, SEXP_t * val) * S-exp and the attribute. */ SEXP_t *nl; + SEXP_t *x_ref; - if (val == NULL) - ns = SEXP_string_new(name, strlen(name)); - else - ns = SEXP_string_newf(":%s", name); - - nl = SEXP_list_new(n_ref, ns, val, NULL); + x_ref = SEXP_list_nth(item, 1); + nl = SEXP_list_new(x_ref, ns, val, NULL); + SEXP_free(x_ref); - SEXP_free(n_ref); - SEXP_free(ns); - - n_ref = SEXP_list_replace(item, 1, nl); + x_ref = SEXP_list_replace(item, 1, nl); + SEXP_free(x_ref); SEXP_free(nl); } SEXP_free(n_ref); + SEXP_free(ns); + return (val); }