diff -uprN a/bindings.c b/bindings.c --- a/bindings.c 2019-01-07 16:16:48.039448823 +0800 +++ b/bindings.c 2019-01-07 16:34:25.904397244 +0800 @@ -3128,9 +3128,10 @@ static unsigned long get_memlimit(const char *memlimit_str = NULL; unsigned long memlimit = 0; - if ((memlimit_str = cgfs_get_value("memory", cgroup, file))) - memlimit = strtoul(memlimit_str, NULL, 10); + if (!(memlimit_str = cgfs_get_value("memory", cgroup, file))) + return memlimit; + memlimit = strtoul(memlimit_str, NULL, 10); free(memlimit_str); memlimit_str = NULL; @@ -3375,9 +3376,10 @@ static long get_cpulimit(const char *cgr char *cpulimit_str = NULL; long cpulimit = -1; - if (cgfs_get_value("cpu", cgroup, file, &cpulimit_str)) - cpulimit = strtol(cpulimit_str, NULL, 10); + if (!cgfs_get_value("cpu", cgroup, file, &cpulimit_str)) + return cpulimit; + cpulimit = strtol(cpulimit_str, NULL, 10); free(cpulimit_str); return cpulimit; @@ -3385,12 +3387,13 @@ static long get_cpulimit(const char *cgr static long get_cpu_count(const char *cgroup) { - char *copy = strdupa(cgroup); + char *copy = must_copy_string(cgroup); long double count = -1; int period, quota; period = get_cpulimit(copy, "cpu.cfs_period_us"); quota = get_cpulimit(copy, "cpu.cfs_quota_us"); + free(copy); if (quota != -1) count = quota / period; @@ -3607,6 +3610,8 @@ err: cpuset = NULL; free(cg); cg = NULL; + free(ccg); + ccg = NULL; return rv; } @@ -3922,6 +3927,8 @@ err: cpuset = NULL; free(cg); cg = NULL; + free(ccg); + ccg = NULL; return rv; }