From: Ziye Yang <ziye.yang@intel.com>
To: dev@dpdk.org
Cc: Ziye Yang <optimistyzy@gmail.com>
Subject: [dpdk-dev] [PATCH v2] linuxapp, eal: Fix the memory leak issue of logid
Date: Thu, 30 Aug 2018 17:22:19 +0800 [thread overview]
Message-ID: <1535620939-11861-1-git-send-email-ziye.yang@intel.com> (raw)
From: Ziye Yang <optimistyzy@gmail.com>
This patch is used to fix the memory leak issue of logid.
We use the ASAN test in SPDK when intergrating DPDK and
find this issue.
Signed-off-by: Ziye Yang <ziye.yang@intel.com>
---
lib/librte_eal/linuxapp/eal/eal.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index e59ac65..0ddd660 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -793,7 +793,7 @@ static void rte_eal_init_alert(const char *msg)
int i, fctret, ret;
pthread_t thread_id;
static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
- const char *logid;
+ char *logid;
char cpuset[RTE_CPU_AFFINITY_STR_LEN];
char thread_name[RTE_MAX_THREAD_NAME_LEN];
@@ -812,6 +812,12 @@ static void rte_eal_init_alert(const char *msg)
logid = strrchr(argv[0], '/');
logid = strdup(logid ? logid + 1: argv[0]);
+ if (!logid) {
+ rte_eal_init_alert("Cannot allocate memory for logid\n");
+ rte_errno = ENOMEM;
+ rte_atomic32_clear(&run_once);
+ return -1;
+ }
thread_id = pthread_self();
@@ -823,6 +829,7 @@ static void rte_eal_init_alert(const char *msg)
if (rte_eal_cpu_init() < 0) {
rte_eal_init_alert("Cannot detect lcores.");
rte_errno = ENOTSUP;
+ free(logid);
return -1;
}
@@ -831,6 +838,7 @@ static void rte_eal_init_alert(const char *msg)
rte_eal_init_alert("Invalid 'command line' arguments.");
rte_errno = EINVAL;
rte_atomic32_clear(&run_once);
+ free(logid);
return -1;
}
@@ -844,6 +852,7 @@ static void rte_eal_init_alert(const char *msg)
if (eal_option_device_parse()) {
rte_errno = ENODEV;
rte_atomic32_clear(&run_once);
+ free(logid);
return -1;
}
@@ -851,8 +860,10 @@ static void rte_eal_init_alert(const char *msg)
if (rte_eal_intr_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
+ free(logid);
return -1;
}
+ free(logid);
/* Put mp channel init before bus scan so that we can init the vdev
* bus through mp channel in the secondary process before the bus scan.
--
1.9.3
reply other threads:[~2018-08-30 9:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1535620939-11861-1-git-send-email-ziye.yang@intel.com \
--to=ziye.yang@intel.com \
--cc=dev@dpdk.org \
--cc=optimistyzy@gmail.com \
/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).