[lxc-devel] [PATCH 2/2] fix some larger memory leaks in cgroup code

Dwight Engen dwight.engen at oracle.com
Wed Sep 25 19:51:41 UTC 2013


On Wed, 25 Sep 2013 14:44:07 -0400
S.Çağlar Onur <caglar at 10ur.org> wrote:

> Uhh something is wrong with this commit

Hey Serge, I think this has to do with the rebase after the split up as
it certinaly wasn't seg faulting on me originally. The split also
appears to have introduced a couple new leaks (ie. line in the
subfunctions). Do you want me to just redo the cleanup fds & memory
stuff on top of your change?

> (178938fe0ac891092205d76f67af855dcf7397af), both go bindings and some
> lxc tools started to seg fault
> sudo lxc-ps
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> Segmentation fault (core dumped)
> CONTAINER   PID TTY          TIME CMD
>           27168 pts/2    00:00:00 ps
>           27169 pts/2    00:00:00 awk
>           27061 pts/2    00:00:00 sudo
>           27062 pts/2    00:00:00 lxc-ps
> 
> reverting 178938fe0a makes things OK again.
> 
> 
> On Tue, Sep 24, 2013 at 7:46 PM, Serge Hallyn
> <serge.hallyn at ubuntu.com>wrote:
> 
> > From: Dwight Engen <dwight.engen at oracle.com>
> >
> > Don't worry about saved_errno since none of the *_free routines
> > will set it
> >
> > Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
> > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> > ---
> >  src/lxc/cgroup.c | 18 ++++++++++--------
> >  1 file changed, 10 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
> > index 72abc2f..730d3b7 100644
> > --- a/src/lxc/cgroup.c
> > +++ b/src/lxc/cgroup.c
> > @@ -296,7 +296,7 @@ static bool find_hierarchy_mountpts( struct
> > cgroup_meta_data *meta_data, char **
> >                 return false;
> >
> >         while (getline(&line, &sz, proc_self_mountinfo) != -1) {
> > -               char *token, *saveptr = NULL;
> > +               char *token, *line_tok, *saveptr = NULL;
> >                 size_t i, j, k;
> >                 struct cgroup_mount_point *mount_point;
> >                 struct cgroup_hierarchy *h;
> > @@ -305,7 +305,7 @@ static bool find_hierarchy_mountpts( struct
> > cgroup_meta_data *meta_data, char **
> >                 if (line[0] && line[strlen(line) - 1] == '\n')
> >                         line[strlen(line) - 1] = '\0';
> >
> > -               for (i = 0; (token = strtok_r(line, " ",
> > &saveptr)); line = NULL) {
> > +               for (i = 0, line_tok = line; (token =
> > strtok_r(line_tok, " ", &saveptr)); line_tok = NULL) {
> >                         r = lxc_grow_array((void ***)&tokens,
> > &token_capacity, i + 1, 64);
> >                         if (r < 0)
> >                                 goto out;
> > @@ -477,6 +477,7 @@ struct cgroup_meta_data
> > *lxc_cgroup_put_meta(struct cgroup_meta_data *meta_data)
> >
> > lxc_cgroup_hierarchy_free(meta_data->hierarchies[i]);
> >         }
> >         free(meta_data->hierarchies);
> > +       free(meta_data);
> >         return NULL;
> >  }
> >
> > @@ -1103,29 +1104,30 @@ char
> > *lxc_cgroup_get_hierarchy_abs_path(const char *subsystem, const
> > char *name, struct cgroup_process_info *base_info, *info;
> >         struct cgroup_mount_point *mp;
> >         char *result = NULL;
> > -       int saved_errno;
> >
> >         meta = lxc_cgroup_load_meta();
> >         if (!meta)
> >                 return NULL;
> >         base_info = lxc_cgroup_get_container_info(name, lxcpath,
> > meta); if (!base_info)
> > -               return NULL;
> > +               goto out1;
> >         info = find_info_for_subsystem(base_info, subsystem);
> >         if (!info)
> > -               return NULL;
> > +               goto out2;
> >         if (info->designated_mount_point) {
> >                 mp = info->designated_mount_point;
> >         } else {
> >                 mp = lxc_cgroup_find_mount_point(info->hierarchy,
> > info->cgroup_path, true);
> >                 if (!mp)
> > -                       return NULL;
> > +                       goto out3;
> >         }
> >         result = cgroup_to_absolute_path(mp, info->cgroup_path,
> > NULL);
> > -       saved_errno = errno;
> > +out3:
> > +       lxc_cgroup_process_info_free(info);
> > +out2:
> >         lxc_cgroup_process_info_free(base_info);
> > +out1:
> >         lxc_cgroup_put_meta(meta);
> > -       errno = saved_errno;
> >         return result;
> >  }
> >
> > --
> > 1.8.3.2
> >
> >
> >
> > ------------------------------------------------------------------------------
> > October Webinars: Code for Performance
> > Free Intel webinars can help you accelerate application performance.
> > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the
> > most from
> > the latest Intel processors and coprocessors. See abstracts and
> > register >
> > http://pubads.g.doubleclick.net/gampad/clk?id=60133471&iu=/4140/ostg.clktrk
> > _______________________________________________ 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