Stephen Gallagher wrote:
> On 06/09/2010 04:11 PM, Dmitri Pal wrote:
>   
>> Fixes #513.
>>
>> Thanks to Steve for helping to find it!
>> Could not see it myself.
>>
>>     
>
>
> Nack. Please address warning:
>
>    CC     ini_config_ut.o
> ../../../common/ini/ini_config_ut.c: In function ‘get_test’:
> ../../../common/ini/ini_config_ut.c:1011: warning: format ‘%ld’ expects 
> type ‘long int’, but argument 2 has type ‘char *’
>
>
>   
Oops... Thanks for catching!
New patch attached.


-- 
Thank you,
Dmitri Pal

Engineering Manager IPA project,
Red Hat Inc.


-------------------------------
Looking to carve out IT costs?
www.redhat.com/carveoutcosts/

From 54d4e3398ac32cc58aab59d4457c0b50edc8623f Mon Sep 17 00:00:00 2001
From: Dmitri Pal <d...@redhat.com>
Date: Wed, 9 Jun 2010 16:08:58 -0400
Subject: [PATCH] [INI] 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.
---
 common/ini/ini_config.c    |    2 ++
 common/ini/ini_config_ut.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/common/ini/ini_config.c b/common/ini/ini_config.c
index f22e203..26d2d4c 100644
--- a/common/ini/ini_config.c
+++ b/common/ini/ini_config.c
@@ -1842,6 +1842,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;
 }
diff --git a/common/ini/ini_config_ut.c b/common/ini/ini_config_ut.c
index 1c82a05..5fe30d7 100644
--- a/common/ini/ini_config_ut.c
+++ b/common/ini/ini_config_ut.c
@@ -976,6 +976,48 @@ int get_test(void)
     COLOUT(for (i=0;i<size;i++) printf("Attribute: [%s]\n", prop_array[i]));
     free_attribute_list(prop_array);
 
+    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;
-- 
1.5.5.6

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to