summaryrefslogtreecommitdiffstats
path: root/common/log.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-04-02 02:42:39 -0600
committerTom Rini <trini@konsulko.com>2018-04-10 11:52:16 -0400
commit45fac9fc186dd5259dfeddc7e86a0d55bb4377bd (patch)
tree83ff64a294e3ccb05a266ccd07de6f394a163c58 /common/log.c
parent004d00914a1888a050ef2d30e52e8e3862983ccb (diff)
downloadu-boot-45fac9fc186dd5259dfeddc7e86a0d55bb4377bd.tar.gz
u-boot-45fac9fc186dd5259dfeddc7e86a0d55bb4377bd.tar.xz
u-boot-45fac9fc186dd5259dfeddc7e86a0d55bb4377bd.zip
log: Correct missing free() on error in log_add_filter()
If there is a problem with the parameters to log_add_filter(), the memory allocated is currently not freed. Fix this. Reported-by: Coverity (CID: 171962) Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/log.c')
-rw-r--r--common/log.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/common/log.c b/common/log.c
index 680a60f86e..66d5e3ebf8 100644
--- a/common/log.c
+++ b/common/log.c
@@ -224,6 +224,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
{
struct log_filter *filt;
struct log_device *ldev;
+ int ret;
int i;
ldev = log_device_find_by_name(drv_name);
@@ -236,8 +237,10 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
if (cat_list) {
filt->flags |= LOGFF_HAS_CAT;
for (i = 0; ; i++) {
- if (i == ARRAY_SIZE(filt->cat_list))
- return -ENOSPC;
+ if (i == ARRAY_SIZE(filt->cat_list)) {
+ ret = -ENOSPC;
+ goto err;
+ }
filt->cat_list[i] = cat_list[i];
if (cat_list[i] == LOGC_END)
break;
@@ -246,17 +249,19 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
filt->max_level = max_level;
if (file_list) {
filt->file_list = strdup(file_list);
- if (!filt->file_list)
- goto nomem;
+ if (!filt->file_list) {
+ ret = ENOMEM;
+ goto err;
+ }
}
filt->filter_num = ldev->next_filter_num++;
list_add_tail(&filt->sibling_node, &ldev->filter_head);
return filt->filter_num;
-nomem:
+err:
free(filt);
- return -ENOMEM;
+ return ret;
}
int log_remove_filter(const char *drv_name, int filter_num)