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

S.Çağlar Onur caglar at 10ur.org
Wed Sep 25 18:44:07 UTC 2013


Uhh something is wrong with this commit
(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
>



-- 
S.Çağlar Onur <caglar at 10ur.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130925/c0967091/attachment.html>


More information about the lxc-devel mailing list