Free the resources when fopen or realloc fails.
Also remove completelly useless code.
Signed-off-by: Jan Safranek <jsafrane@redhat.com>
Acked-by: Dhaval Giani <dhaval.giani@gmail.com>
if (access(cgroup_path, F_OK))
return ECGROUPUNSUPP;
- /*
- * Read all the procs and then sort them up.
- */
-
- tmp_list = *pids;
-
/*
* Keep doubling the memory allocated if needed
*/
procs = fopen(cgroup_path, "r");
if (!procs) {
last_errno = errno;
+ free(tmp_list);
+ *pids = NULL;
+ *size = 0;
return ECGOTHER;
}
n++;
}
if (!feof(procs)) {
+ pid_t *orig_list = tmp_list;
tot_procs *= 2;
tmp_list = realloc(tmp_list, sizeof(pid_t) * tot_procs);
if (!tmp_list) {
last_errno = errno;
+ fclose(procs);
+ free(orig_list);
+ *pids = NULL;
+ *size = 0;
return ECGOTHER;
}
}