DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kuba Kozak <kubax.kozak@intel.com>
To: dev@dpdk.org
Cc: harry.van.haaren@intel.com, deepak.k.jain@intel.com,
	michalx.k.jastrzebski@intel.com, kubax.kozak@intel.com
Subject: [dpdk-dev] [PATCH] proc-info: wrong sizeof argument in malloc function
Date: Tue,  9 May 2017 07:23:29 +0200	[thread overview]
Message-ID: <1494307409-20019-1-git-send-email-kubax.kozak@intel.com> (raw)

From: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>

Coverity reported that an argument for sizeof was used improperly. 
We should allocate memory for value size that pointer points to,
instead of pointer size itself. 

Coverity issue: 144523, 144521
Fixes: 7ac16a3660c0 ("app/proc-info: support xstats by ID and by name")

Signed-off-by: Michal Jastrzebski <michalx.k.jastrzebski@intel.com>
---
 app/proc_info/main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/proc_info/main.c b/app/proc_info/main.c
index 17a1c87..d4f6a82 100644
--- a/app/proc_info/main.c
+++ b/app/proc_info/main.c
@@ -434,7 +434,7 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
 	int ret, i;
 	static const char *nic_stats_border = "########################";
 
-	values = malloc(sizeof(values) * len);
+	values = malloc(sizeof(*values) * len);
 	if (values == NULL) {
 		printf("Cannot allocate memory for xstats\n");
 		return;
@@ -486,7 +486,7 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
 		printf("Cannot get xstats count\n");
 		return;
 	}
-	values = malloc(sizeof(values) * len);
+	values = malloc(sizeof(*values) * len);
 	if (values == NULL) {
 		printf("Cannot allocate memory for xstats\n");
 		return;
-- 
1.7.9.5

             reply	other threads:[~2017-05-09  5:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-09  5:23 Kuba Kozak [this message]
2017-05-09  8:44 ` Van Haaren, Harry
2017-05-10 16:50   ` Thomas Monjalon

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=1494307409-20019-1-git-send-email-kubax.kozak@intel.com \
    --to=kubax.kozak@intel.com \
    --cc=deepak.k.jain@intel.com \
    --cc=dev@dpdk.org \
    --cc=harry.van.haaren@intel.com \
    --cc=michalx.k.jastrzebski@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).