summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSemun Lee <semun.lee@samsung.com>2017-07-13 01:48:13 (GMT)
committerSemun Lee <semun.lee@samsung.com>2017-07-13 02:38:37 (GMT)
commitc0a4c174740a1dc1eb9f8f04576eeb89601ce823 (patch)
treef1890ed0a8163bf886fc335c20396bbf6fa8a02f
parent48d5d8cda7b958cde2f64a6b1e9256b24aea2f1d (diff)
downloadapplication-c0a4c174740a1dc1eb9f8f04576eeb89601ce823.zip
application-c0a4c174740a1dc1eb9f8f04576eeb89601ce823.tar.gz
application-c0a4c174740a1dc1eb9f8f04576eeb89601ce823.tar.bz2
Use seperated variable for realloc return valuerefs/changes/82/138582/2
Using the same variable for return value and input parameter of realloc() may cause memory leak when realloc() fails to allocate new memory. Change-Id: If2ee2134b272e6fc158fc400dc352704d81b0e24 Signed-off-by: Semun Lee <semun.lee@samsung.com>
-rwxr-xr-xpreference/preference.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/preference/preference.c b/preference/preference.c
index 6e78b4e..246f011 100755
--- a/preference/preference.c
+++ b/preference/preference.c
@@ -830,6 +830,7 @@ static int _preference_get_key_filesys(keynode_t *keynode, int* io_errno)
double value_dbl = 0;
char file_buf[BUF_LEN] = {0,};
char *value = NULL;
+ char *tmp_value;
int value_size = 0;
retry_open:
@@ -948,11 +949,14 @@ retry:
while (fgets(file_buf, sizeof(file_buf), fp)) {
if (value) {
value_size = value_size + strlen(file_buf);
- value = (char *) realloc(value, value_size);
- if (value == NULL) {
+ tmp_value = (char *) realloc(value, value_size);
+ if (tmp_value == NULL) {
func_ret = PREFERENCE_ERROR_OUT_OF_MEMORY;
+ free(value);
+ value = NULL;
break;
}
+ value = tmp_value;
strncat(value, file_buf, strlen(file_buf));
} else {
value_size = strlen(file_buf) + 1;