From: Andrea Claudi <aclaudi@redhat.com>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, dsahern@gmail.com
Subject: [PATCH iproute2 1/2] devlink: fix memory leak in cmd_dev_flash()
Date: Fri, 11 Dec 2020 19:53:02 +0100 [thread overview]
Message-ID: <0552db30b97ec8db87d82ef5d6def490510ce6aa.1607712061.git.aclaudi@redhat.com> (raw)
In-Reply-To: <cover.1607712061.git.aclaudi@redhat.com>
nlg_ntf is dinamically allocated in mnlg_socket_open(), and is freed on
the out: return path. However, some error paths do not free it,
resulting in memory leak.
This commit fix this using mnlg_socket_close(), and reporting the
correct error number when required.
Fixes: 9b13cddfe268 ("devlink: implement flash status monitoring")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
---
devlink/devlink.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index ca99732e..43549965 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -3371,19 +3371,21 @@ static int cmd_dev_flash(struct dl *dl)
err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
if (err)
- return err;
+ goto err_socket;
err = pipe(pipe_fds);
- if (err == -1)
- return -errno;
+ if (err == -1) {
+ err = -errno;
+ goto err_socket;
+ }
pipe_r = pipe_fds[0];
pipe_w = pipe_fds[1];
pid = fork();
if (pid == -1) {
- close(pipe_r);
close(pipe_w);
- return -errno;
+ err = -errno;
+ goto out;
} else if (!pid) {
/* In child, just execute the flash and pass returned
* value through pipe once it is done.
@@ -3412,6 +3414,7 @@ static int cmd_dev_flash(struct dl *dl)
err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
out:
close(pipe_r);
+err_socket:
mnlg_socket_close(nlg_ntf);
return err;
}
--
2.29.2
next prev parent reply other threads:[~2020-12-11 20:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 18:53 [PATCH iproute2 0/2] fix two memory leaks Andrea Claudi
2020-12-11 18:53 ` Andrea Claudi [this message]
2020-12-11 18:53 ` [PATCH iproute2 2/2] tc: pedit: fix memory leak in print_pedit Andrea Claudi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0552db30b97ec8db87d82ef5d6def490510ce6aa.1607712061.git.aclaudi@redhat.com \
--to=aclaudi@redhat.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).