From 2f2f63a8c96ecd07e481b2d28f03ce0e82c55f5a Mon Sep 17 00:00:00 2001 From: Igor Peshansky Date: Mon, 12 Sep 2016 13:07:52 -0400 Subject: [PATCH] Address more review comments: - Locking fixes, - Leak fixes. --- src/daemon/meta_data.c | 14 ++++++++------ src/target_set.c | 9 ++++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c index d26570e9..a11fccb2 100644 --- a/src/daemon/meta_data.c +++ b/src/daemon/meta_data.c @@ -739,6 +739,7 @@ int meta_data_as_string (meta_data_t *md, /* {{{ */ char *actual; char buffer[MD_MAX_NONSTRING_CHARS]; /* For non-string types. */ char *temp; + int type; if ((md == NULL) || (key == NULL) || (value == NULL)) return (-EINVAL); @@ -752,7 +753,9 @@ int meta_data_as_string (meta_data_t *md, /* {{{ */ return (-ENOENT); } - switch (e->type) + type = e->type; + + switch (type) { case MD_TYPE_STRING: actual = e->value.mv_string; @@ -774,21 +777,20 @@ int meta_data_as_string (meta_data_t *md, /* {{{ */ break; default: pthread_mutex_unlock (&md->lock); - ERROR ("meta_data_as_string: unknown type %d for key `%s'", - e->type, e->key); + ERROR ("meta_data_as_string: unknown type %d for key `%s'", type, key); return (-ENOENT); } + pthread_mutex_unlock (&md->lock); + temp = md_strdup (actual); if (temp == NULL) { pthread_mutex_unlock (&md->lock); - ERROR ("meta_data_as_string: md_strdup failed for key `%s'.", e->key); + ERROR ("meta_data_as_string: md_strdup failed for key `%s'.", key); return (-ENOMEM); } - pthread_mutex_unlock (&md->lock); - *value = temp; return (0); diff --git a/src/target_set.c b/src/target_set.c index 95f03173..3de86e48 100644 --- a/src/target_set.c +++ b/src/target_set.c @@ -43,12 +43,12 @@ static void ts_key_list_free (ts_key_list_t *l) /* {{{ */ if (l == NULL) return; - free (l->key); + sfree (l->key); if (l->next != NULL) ts_key_list_free (l->next); - free (l); + sfree (l); } /* }}} void ts_name_list_free */ struct ts_data_s @@ -153,13 +153,16 @@ static int ts_config_add_meta_delete (ts_key_list_t **dest, /* {{{ */ } if (cf_util_get_string (ci, &entry->key) != 0) + { + ts_key_list_free (entry); return (-1); /* An error has already been reported. */ + } if (strlen (entry->key) == 0) { ERROR ("Target `set': The `%s' option does not accept empty string as " "first argument.", ci->key); - sfree (entry->key); + ts_key_list_free (entry); return (-1); } -- 2.30.2