From: Yong Wang <wang.yong19@zte.com.cn>
To: ferruh.yigit@intel.com
Cc: dev@dpdk.org, Yong Wang <wang.yong19@zte.com.cn>
Subject: [dpdk-dev] [PATCH] linuxapp/eal: fix memory leak
Date: Wed, 20 Sep 2017 06:08:52 -0400 [thread overview]
Message-ID: <1505902132-30967-1-git-send-email-wang.yong19@zte.com.cn> (raw)
In func rte_eal_init(), dynamic memory stored in 'logid' allocated
through func 'strdup' is lost when return. Fix it by freeing the memory
before return.
Signed-off-by: Yong Wang <wang.yong19@zte.com.cn>
---
lib/librte_eal/linuxapp/eal/eal.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 48f12f4..c2f9843 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -751,7 +751,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];
@@ -781,6 +781,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;
}
@@ -789,6 +790,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;
}
@@ -799,6 +801,7 @@ static void rte_eal_init_alert(const char *msg)
rte_eal_init_alert("Cannot get hugepage information.");
rte_errno = EACCES;
rte_atomic32_clear(&run_once);
+ free(logid);
return -1;
}
@@ -826,6 +829,7 @@ static void rte_eal_init_alert(const char *msg)
rte_eal_init_alert("Cannot init logging.");
rte_errno = ENOMEM;
rte_atomic32_clear(&run_once);
+ free(logid);
return -1;
}
@@ -834,6 +838,7 @@ static void rte_eal_init_alert(const char *msg)
rte_eal_init_alert("Cannot init VFIO\n");
rte_errno = EAGAIN;
rte_atomic32_clear(&run_once);
+ free(logid);
return -1;
}
#endif
@@ -841,6 +846,7 @@ static void rte_eal_init_alert(const char *msg)
if (rte_eal_memory_init() < 0) {
rte_eal_init_alert("Cannot init memory\n");
rte_errno = ENOMEM;
+ free(logid);
return -1;
}
@@ -850,24 +856,28 @@ static void rte_eal_init_alert(const char *msg)
if (rte_eal_memzone_init() < 0) {
rte_eal_init_alert("Cannot init memzone\n");
rte_errno = ENODEV;
+ free(logid);
return -1;
}
if (rte_eal_tailqs_init() < 0) {
rte_eal_init_alert("Cannot init tail queues for objects\n");
rte_errno = EFAULT;
+ free(logid);
return -1;
}
if (rte_eal_alarm_init() < 0) {
rte_eal_init_alert("Cannot init interrupt-handling thread\n");
/* rte_eal_alarm_init sets rte_errno on failure. */
+ free(logid);
return -1;
}
if (rte_eal_timer_init() < 0) {
rte_eal_init_alert("Cannot init HPET or TSC timers\n");
rte_errno = ENOTSUP;
+ free(logid);
return -1;
}
@@ -886,17 +896,20 @@ 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;
}
if (eal_option_device_parse()) {
rte_errno = ENODEV;
+ free(logid);
return -1;
}
if (rte_bus_scan()) {
rte_eal_init_alert("Cannot scan the buses for devices\n");
rte_errno = ENODEV;
+ free(logid);
return -1;
}
@@ -941,6 +954,7 @@ static void rte_eal_init_alert(const char *msg)
if (ret) {
rte_eal_init_alert("rte_service_init() failed\n");
rte_errno = ENOEXEC;
+ free(logid);
return -1;
}
@@ -948,6 +962,7 @@ static void rte_eal_init_alert(const char *msg)
if (rte_bus_probe()) {
rte_eal_init_alert("Cannot probe devices\n");
rte_errno = ENOTSUP;
+ free(logid);
return -1;
}
@@ -957,10 +972,12 @@ static void rte_eal_init_alert(const char *msg)
ret = rte_service_start_with_defaults();
if (ret < 0 && ret != -ENOTSUP) {
rte_errno = ENOEXEC;
+ free(logid);
return -1;
}
rte_eal_mcfg_complete();
+ free(logid);
return fctret;
}
--
1.8.3.1
next reply other threads:[~2017-09-20 10:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-20 10:08 Yong Wang [this message]
2017-10-24 0:06 ` Ferruh Yigit
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=1505902132-30967-1-git-send-email-wang.yong19@zte.com.cn \
--to=wang.yong19@zte.com.cn \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.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).