lkml.org 
[lkml]   [2013]   [Dec]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 01/14] tools lib traceevent: Get rid of malloc_or_die() in show_error()
Em Mon, Dec 09, 2013 at 02:03:42PM -0500, Steven Rostedt escreveu:
> On Mon, 9 Dec 2013 15:30:09 -0300
> Arnaldo Carvalho de Melo <acme@ghostprotocols.net> wrote:
>
>
> > > + error = malloc(MAX_ERR_STR_SIZE);
> > > + if (error == NULL) {
> > > + /* no memory */
> > > + *error_str = "failed to allocate memory";
> > > + return;
> >
> > Can *error_str point to either malloc'ed or constant strings? Who
> > releases the allocated memory?
> >
>
> Good question. Perhaps we should have a flag that states if the string
> is allocated or not. Or better yet, since the only reason it would be
> pointing to a static string is if the string for error_str itself
> failed to allocate. Then we could use a string within pevent for it:
>
> static char *pevent_failed_error_alloc = "failed to allocate memory";
>
> Then in the freeing of error str:
>
> void pevent_free_error_str(error_str)
> {
> if (error_str != pevent_failed_error_alloc)
> free(error_str);
> }

That is a possibility, yes, then any other routine that works in such a
way could check against this string, but what is wrong with returning a
value to that function and checking against < 0?

- Arnaldo


\
 
 \ /
  Last update: 2013-12-09 21:01    [W:0.206 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site