summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Kowalski <h.kowalski@samsung.com>2021-10-19 16:59:24 +0200
committerHubert Kowalski <h.kowalski@samsung.com>2021-10-22 10:02:04 +0200
commit1275ffae299f66e3c67bd8fce9ecbac3982393c7 (patch)
tree40ba044b916ce464aa90cd521cfede12bfbcd912
parented3f365db479cbea9785656c4795a2058c5f7f1e (diff)
downloadlibusbg-tizen_8.0.tar.gz
libusbg-tizen_8.0.tar.bz2
libusbg-tizen_8.0.zip
This commit fixes potential issue caused by bad allocation. Which causes operating on unallocated memory. Change-Id: I4d5291bde4504fce1ed1e13d596d83270f38bf40
-rw-r--r--src/usbg.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/usbg.c b/src/usbg.c
index 09ba767..a87650f 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1810,19 +1810,19 @@ static int usbg_get_strs_langs_by_path(const char *epath, const char *name,
n = snprintf(spath, sizeof(spath), "%s/%s/%s", epath, name,
STRINGS_DIR);
if (n >= sizeof(spath)) {
- ret = USBG_ERROR_PATH_TOO_LONG;
- goto out;
+ return USBG_ERROR_PATH_TOO_LONG;
}
n = scandir(spath, &dent, file_select, alphasort);
if (n < 0) {
- ret = usbg_translate_error(errno);
- goto out;
+ return usbg_translate_error(errno);
}
buf = calloc(n + 1, sizeof(*buf));
- if (!buf)
+ if (buf == NULL) {
ret = USBG_ERROR_NO_MEM;
+ goto out;
+ }
/* Keep the buffer 0 terminated */
buf[n] = 0;
@@ -1837,15 +1837,17 @@ static int usbg_get_strs_langs_by_path(const char *epath, const char *name,
else
ret = USBG_ERROR_OTHER_ERROR;
}
- free(dent[i]);
}
- free(dent);
if (ret != USBG_SUCCESS)
free(buf);
else
*langs = buf;
out:
+ for (i = 0; i < n; i++) {
+ free(dent[i]);
+ }
+ free(dent);
return ret;
}