[dpdk-dev] [PATCH] proc-info: wrong sizeof argument in malloc function

Van Haaren, Harry harry.van.haaren at intel.com
Tue May 9 10:44:48 CEST 2017


> From: Kozak, KubaX
> Sent: Tuesday, May 9, 2017 6:23 AM
> To: dev at dpdk.org
> Cc: Van Haaren, Harry <harry.van.haaren at intel.com>; Jain, Deepak K <deepak.k.jain at intel.com>;
> Jastrzebski, MichalX K <michalx.k.jastrzebski at intel.com>; Kozak, KubaX <kubax.kozak at intel.com>
> Subject: [PATCH] proc-info: wrong sizeof argument in malloc function
> 
> From: Michal Jastrzebski <michalx.k.jastrzebski at 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 at intel.com>


Please consider merging these in 17.05, this is an important fix for 32 bit systems.

Acked-by: Harry van Haaren <harry.van.haaren at intel.com>



Details:
64 bit system: sizeof(uint64_t*) == sizeof(uint64_t)
32 bit system: sizeof(uint64_t*) != sizeof(uint64_t)

uint64_t *values;

> -	values = malloc(sizeof(values) * len);
> +	values = malloc(sizeof(*values) * len);

The change here ensures that we allocate sizeof(uint64_t) * len, instead of the incorrect sizeof(void *) * len.

Previously on 32 bit systems, only half of the memory required would be allocated.


More information about the dev mailing list