* [U-Boot] [PATCH] log: Correct missing free() on error in log_add_filter()
@ 2018-04-02 8:42 Simon Glass
2018-04-11 14:05 ` [U-Boot] " Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Simon Glass @ 2018-04-02 8:42 UTC (permalink / raw)
To: u-boot
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>
---
common/log.c | 17 +++++++++++------
1 file 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)
--
2.17.0.rc1.321.gba9d0f2565-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] log: Correct missing free() on error in log_add_filter()
2018-04-02 8:42 [U-Boot] [PATCH] log: Correct missing free() on error in log_add_filter() Simon Glass
@ 2018-04-11 14:05 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2018-04-11 14:05 UTC (permalink / raw)
To: u-boot
On Mon, Apr 02, 2018 at 02:42:39AM -0600, Simon Glass wrote:
> 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>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180411/15621426/attachment.sig>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-11 14:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-02 8:42 [U-Boot] [PATCH] log: Correct missing free() on error in log_add_filter() Simon Glass
2018-04-11 14:05 ` [U-Boot] " Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.