]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
Fix a memory leak in "cgconfig" service.
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Wed, 9 Dec 2009 06:47:26 +0000 (15:47 +0900)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Wed, 16 Dec 2009 08:36:39 +0000 (14:06 +0530)
Hi,

When I operated "cgconfig" service on valgrind, I found a memory leak
like the following:

  # cat /etc/cgconfig.conf
  mount {
    cpuset = /cgroup/cpuset;
    cpu    = /cgroup/cpu;
    memory = /cgroup/memory;
  }
  group user000 {
    cpuset {
        cpuset.cpus = 0;
        cpuset.mems = 0;
    }
  }
  group user000/sleep000 {
    cpuset {
        cpuset.cpus = 0;
        cpuset.mems = 0;
    }
  }

  # valgrind --tool=memcheck --leak-check=yes cgconfigparser -l /etc/cgconfig.conf
  ==13095== Memcheck, a memory error detector.
  ==13095== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
  ==13095== Using LibVEX rev 1658, a library for dynamic binary translation.
  ==13095== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
  ==13095== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
  ==13095== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
  ==13095== For more details, rerun with: -v
  ==13095==
  ==13095==
  ==13095== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 1)
  ==13095== malloc/free: in use at exit: 43,062 bytes in 10 blocks.
  ==13095== malloc/free: 129 allocs, 119 frees, 85,399 bytes allocated.
  ==13095== For counts of detected errors, rerun with: -v
  ==13095== searching for pointers to 10 not-freed blocks.
  ==13095== checked 6,795,480 bytes.
  ==13095==
  ==13095== 28 bytes in 2 blocks are definitely lost in loss record 1 of 5
  ==13095==    at 0x4A0590B: realloc (vg_replace_malloc.c:306)
  ==13095==    by 0x4C0CC24: yyparse (parse.y:117)
  ==13095==    by 0x4C12914: cgroup_config_load_config (config.c:467)
  ==13095==    by 0x4008A2: main (cgconfig.c:60)
  ==13095==
  ==13095== LEAK SUMMARY:
  ==13095==    definitely lost: 28 bytes in 2 blocks.
  ==13095==      possibly lost: 0 bytes in 0 blocks.
  ==13095==    still reachable: 43,034 bytes in 8 blocks.
  ==13095==         suppressed: 0 bytes in 0 blocks.
  ==13095== Reachable blocks (those to which a pointer was found) are not shown.
  ==13095== To see them, rerun with: --show-reachable=yes
  #

This patch fixes the memory leak.

Thanks
Ken'ichi Ohmichi

Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
src/parse.y

index d1f8678e5cc8806d316f8a99200f0f04c9bf64fe..45de0eb2937be3a2f0cae591772e9e0ec95c359e 100644 (file)
@@ -130,6 +130,7 @@ namevalue_conf
                if ($1) {
                        $2 = strncat($2, ":", strlen(":"));
                        $$ = strncat($2, $1, strlen($1));
+                       free($1);
                }
                free($4);
        }