I've verified the patch fixes the memory leak.

Before:

289,792 bytes in 1 blocks are definitely lost in loss record 17 of 18
    at 0x4026011: calloc (vg_replace_malloc.c:593)
    by 0x404AACA: cgroup_parse_config (config.c:1023)
    by 0x404ACB6: cgroup_init_templates_cache (config.c:1508)
    by 0x804AE9C: main (cgrulesengd.c:1191)

697,818 (289,792 direct, 408,026 indirect) bytes in 1 blocks are 
definitely lost in loss record 18 of 18
    at 0x4026011: calloc (vg_replace_malloc.c:593)
    by 0x404AAA4: cgroup_parse_config (config.c:1017)
    by 0x404ACB6: cgroup_init_templates_cache (config.c:1508)
    by 0x804AE9C: main (cgrulesengd.c:1191)

LEAK SUMMARY:
    definitely lost: 579,584 bytes in 2 blocks
    indirectly lost: 408,026 bytes in 94 blocks
      possibly lost: 0 bytes in 0 blocks
    still reachable: 1,048,858 bytes in 166 blocks
         suppressed: 0 bytes in 0 blocks

After:

HEAP SUMMARY:
     in use at exit: 1,048,870 bytes in 167 blocks
   total heap usage: 1,728 allocs, 1,561 frees, 2,258,423 bytes allocated

LEAK SUMMARY:
    definitely lost: 0 bytes in 0 blocks
    indirectly lost: 0 bytes in 0 blocks
      possibly lost: 0 bytes in 0 blocks
    still reachable: 1,048,870 bytes in 167 blocks
         suppressed: 0 bytes in 0 blocks

peter

On 25/10/13 16:03, Ivana Hutarova Varekova wrote:
> cgroup_{reload|init}_cached_templates does not free memory if no template
> is set. This patch fix the problem.
>
> Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
Acked-by: Peter Schiffer <pschi...@redhat.com>
> ---
>
>   src/config.c |   13 +++++++++++--
>   1 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/src/config.c b/src/config.c
> index 7240ec1..57703dc 100644
> --- a/src/config.c
> +++ b/src/config.c
> @@ -1468,7 +1468,7 @@ int cgroup_reload_cached_templates(char *pathname)
>       }
>       template_table_index = 0;
>
> -     if (config_template_table_index != 0) {
> +     if ((config_template_table_index != 0) || (config_table_index != 0)) {
>               /* config template structures have to be free as well*/
>               cgroup_free_config();
>       }
> @@ -1523,7 +1523,16 @@ int cgroup_init_templates_cache(char *pathname)
>       int ret = 0;
>       int i;
>
> -     if (config_template_table_index != 0) {
> +     if (template_table) {
> +             /* template structures have to be free */
> +             for (i = 0; i < template_table_index; i++)
> +                     cgroup_free_controllers(&template_table[i]);
> +             free(template_table);
> +             template_table = NULL;
> +     }
> +     template_table_index = 0;
> +
> +     if ((config_template_table_index != 0) || (config_table_index != 0)) {
>               /* config structures have to be clean */
>               cgroup_free_config();
>       }
>
>
> ------------------------------------------------------------------------------
> 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=60135991&iu=/4140/ostg.clktrk
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel
>


------------------------------------------------------------------------------
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=60135991&iu=/4140/ostg.clktrk
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to