lkml.org 
[lkml]   [2018]   [Mar]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 08/19] perf tools: Add mem2node object
On Thu, Mar 08, 2018 at 09:58:49AM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

> > I don't think we need nentries.. AFAIK realloc works ok over single variable
>
> So:
>
> 1) you alloc entries with a max number of entries
>
> 2) you go on populating it
>
> 3) there are some left, lets shrink it:
>
> entries = realloc(entries, nr_entries * sizeof(entries[0]);
>
> Here it will probably not fail, but you check it anyway, and that is
> right, what happens if this returns NULL? entries gets set to NULL,
> we lose the reference to the allocated memory and you return -ENOMEM,
> right?
>
> We end up leaking entries when what I'm suggesting you to do is to
> not clobber entries with the return of realloc() (doing it this way most
> of the time leads to bugs), but instead store it to a temp var
> (nentries), and if it succeeds, then you know that you can
> set nentries to entries and go ahead with your nicely shrunk block of
> memory.
>
> If it fails, then you continue with the original block of memory, that
> continues to have what you just set up, etc.

ah that ;-) ok, will fix

thanks,
jirka

\
 
 \ /
  Last update: 2018-03-08 14:18    [W:0.043 / U:10.452 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site