summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}