summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-06-10 12:35:05 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-06-28 08:38:14 -0400
commite67e64ddefb993f7fdea4501f7efbe657cb0f164 (patch)
tree78f3184b5b90983096146d2f34fda29e1a293f36
parent9d3bd4b906fbfc879cec06d9cdad44db7c15c5ff (diff)
downloadsssd-e67e64ddefb993f7fdea4501f7efbe657cb0f164.tar.gz
sssd-e67e64ddefb993f7fdea4501f7efbe657cb0f164.tar.bz2
sssd-e67e64ddefb993f7fdea4501f7efbe657cb0f164.zip
Memory leak in case of empty value
Addressing coverity issue. Ticket #513. The memory was really leaked when the configuration value was empty. Added unit test that confirmed the bug. MANUAL MERGE.
-rw-r--r--common/ini/ini_config_ut.c42
-rw-r--r--common/ini/ini_get_array.c2
2 files changed, 44 insertions, 0 deletions
diff --git a/common/ini/ini_config_ut.c b/common/ini/ini_config_ut.c
index b88b769a..a1ac52ce 100644
--- a/common/ini/ini_config_ut.c
+++ b/common/ini/ini_config_ut.c
@@ -1205,6 +1205,48 @@ int get_test(void)
/***************************************/
+ COLOUT(printf("Get empty array item\n"));
+
+ item = NULL;
+ error = get_config_item("domains/EXAMPLE.COM",
+ "empty_value",
+ ini_config,
+ &item);
+ if(error) {
+ printf("Expected success but got error! %d\n", error);
+ free_ini_config(ini_config);
+ return error;
+ }
+
+ /* Item should be found */
+ if (item == NULL) {
+ printf("Expected success but got NULL.\n");
+ free_ini_config(ini_config);
+ return -1;
+ }
+
+ COLOUT(col_debug_item(item));
+
+ error = 0;
+ size = 0; /* Here size is not optional!!! */
+ strarray = get_string_config_array(item, ",", &size, &error);
+ if(error) {
+ printf("Expect success got error %d.\n", error);
+ free_ini_config(ini_config);
+ return error;
+ }
+
+ if (size != 0) {
+ for (i=0; i<size; i++) printf("%s\n", *(strarray + i));
+ printf("Expected size=0, got size=%d\n", size);
+ free_string_config_array(strarray);
+ free_ini_config(ini_config);
+ return -1;
+ }
+
+
+ free_string_config_array(strarray);
+
free_ini_config(ini_config);
COLOUT(printf("Done with get test!\n"));
return EOK;
diff --git a/common/ini/ini_get_array.c b/common/ini/ini_get_array.c
index c2c6362a..b2cbfacf 100644
--- a/common/ini/ini_get_array.c
+++ b/common/ini/ini_get_array.c
@@ -162,6 +162,8 @@ static char **get_str_cfg_array(struct collection_item *item,
if (error) *error = EOK;
if (size) *size = count;
+ /* If count is 0 the copy needs to be freed */
+ if (count == 0) free(copy);
TRACE_FLOW_STRING("get_str_cfg_array", "Exit");
return array;
}