diff options
author | Victor Hakoun <victor.hakoun@eurogiciel.fr> | 2013-06-12 17:01:06 +0200 |
---|---|---|
committer | Victor Hakoun <victor.hakoun@eurogiciel.fr> | 2013-06-12 17:01:06 +0200 |
commit | ee4fcd1366b2b7a86d3a5b8535d5f6d3a32a6106 (patch) | |
tree | 808bf1bed351d9032db2214a394ee8ad0634d843 /vconf.c | |
parent | 4aeec7d05ec1a44340f580f5da478251a84e13da (diff) | |
download | vconf-ee4fcd1366b2b7a86d3a5b8535d5f6d3a32a6106.tar.gz vconf-ee4fcd1366b2b7a86d3a5b8535d5f6d3a32a6106.tar.bz2 vconf-ee4fcd1366b2b7a86d3a5b8535d5f6d3a32a6106.zip |
Fix possible memory leak
- 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.
Diffstat (limited to 'vconf.c')
-rwxr-xr-x | vconf.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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; |