Fix possible memory leak 72/3972/1
authorVictor Hakoun <victor.hakoun@eurogiciel.fr>
Wed, 12 Jun 2013 15:01:06 +0000 (17:01 +0200)
committerVictor Hakoun <victor.hakoun@eurogiciel.fr>
Wed, 12 Jun 2013 15:01:06 +0000 (17:01 +0200)
- see realloc man :
The realloc() function returns a pointer to the newly allocated memory, which is suitably aligned for any kind of variable and may be different from ptr, or NULL if the request fails.  If size was equal to 0, either NULL or a pointer suitable to be passed to free() is returned.  If realloc() fails the original block is left untouched; it is not freed or moved.

vconf.c

diff --git a/vconf.c b/vconf.c
index 11bd47e35a75863049507311a353a871b5305425..45ebd15b7b9c31a72faceff598b82b64df0adfaf 100755 (executable)
--- a/vconf.c
+++ b/vconf.c
@@ -1574,6 +1574,7 @@ static int _vconf_get_key_elektra_format(keynode_t *keynode, FILE *fp)
        int err_no = 0;
        char err_buf[100] = { 0, };
        int func_ret = VCONF_OK;
+       char tmp;
 
        INFO("_vconf_get_key_elektra_format start");
 
@@ -1620,11 +1621,13 @@ static int _vconf_get_key_elektra_format(keynode_t *keynode, FILE *fp)
        {
                if(value) {
                        value_size = value_size + strlen(file_buf);
-                       value = (char *) realloc(value, value_size);
-                       if(value == NULL) {
+                       tmp = (char *) realloc(value, value_size);
+                       if(!tmp) {
+                               free(value);
                                func_ret = VCONF_ERROR_NO_MEM;
                                break;
                        }
+                       value = tmp;
                        strncat(value, file_buf, strlen(file_buf));
                } else {
                        value_size = strlen(file_buf) + 1;