[lxc-devel] [PATCH] fix getline(3) memory leaks

Dwight Engen dwight.engen at oracle.com
Tue May 21 22:59:29 UTC 2013


On Tue, 21 May 2013 17:07:54 -0500
Serge Hallyn <serge.hallyn at ubuntu.com> wrote:

> Quoting Dwight Engen (dwight.engen at oracle.com):
> > Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
> > ---
> >  src/lxc/attach.c | 2 +-
> >  src/lxc/cgroup.c | 1 +
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/lxc/attach.c b/src/lxc/attach.c
> > index a7e9074..d8b4915 100644
> > --- a/src/lxc/attach.c
> > +++ b/src/lxc/attach.c
> > @@ -114,6 +114,7 @@ struct lxc_proc_context_info
> > *lxc_proc_get_context_info(pid_t pid) }
> >  	}
> >  
> 
> does this need to be
> 
> 	if (line)
> 		free(line);
> ?

Hmm, I guess that would be good defensive programming but it seemed
unlikely to me that getline() would find no lines
in /proc/<pid>/status. line was initialized to NULL, so at worst we'd
free(NULL), which I guess not every free() handles well. If you think
we should put the if in I'm fine with that :)

> > +	free(line);
> >  	fclose(proc_file);
> >  
> >  	if (!found) {
> > @@ -145,7 +146,6 @@ struct lxc_proc_context_info
> > *lxc_proc_get_context_info(pid_t pid) 
> >  out_error:
> >  	free(info);
> > -	free(line);
> >  	return NULL;
> >  }
> >  
> > diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
> > index 44266de..2ffbb54 100644
> > --- a/src/lxc/cgroup.c
> > +++ b/src/lxc/cgroup.c
> > @@ -503,6 +503,7 @@ static char *get_all_cgroups(void)
> >  	}
> >  
> >  out:
> > +	free(line);
> >  	fclose(f);
> >  	return ret;
> >  }
> > -- 
> > 1.8.1.4
> > 
> > 
> > ------------------------------------------------------------------------------
> > Try New Relic Now & We'll Send You this Cool Shirt
> > New Relic is the only SaaS-based application performance monitoring
> > service that delivers powerful full stack analytics. Optimize and
> > monitor your browser, app, & servers with just a few lines of code.
> > Try New Relic and get this awesome Nerd Life shirt!
> > http://p.sf.net/sfu/newrelic_d2d_may
> > _______________________________________________ Lxc-devel mailing
> > list Lxc-devel at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/lxc-devel





More information about the lxc-devel mailing list