On Wed, Aug 24, 2011 at 4:40 AM, Jan Safranek <jsafr...@redhat.com> wrote: > Free the resources when fopen or realloc fails. > Also remove completelly useless code. > > Signed-off-by: Jan Safranek <jsafr...@redhat.com>
Acked-by: Dhaval Giani <dhaval.gi...@gmail.com> > --- > > src/api.c | 14 ++++++++------ > 1 files changed, 8 insertions(+), 6 deletions(-) > > diff --git a/src/api.c b/src/api.c > index 5b2b518..2ed9e22 100644 > --- a/src/api.c > +++ b/src/api.c > @@ -3883,12 +3883,6 @@ int cgroup_get_procs(char *name, char *controller, > pid_t **pids, int *size) > return ECGROUPUNSUPP; > > /* > - * Read all the procs and then sort them up. > - */ > - > - tmp_list = *pids; > - > - /* > * Keep doubling the memory allocated if needed > */ > tmp_list= malloc(sizeof(pid_t) * tot_procs); > @@ -3900,6 +3894,9 @@ int cgroup_get_procs(char *name, char *controller, > pid_t **pids, int *size) > procs = fopen(cgroup_path, "r"); > if (!procs) { > last_errno = errno; > + free(tmp_list); > + *pids = NULL; > + *size = 0; > return ECGOTHER; > } > > @@ -3913,10 +3910,15 @@ int cgroup_get_procs(char *name, char *controller, > pid_t **pids, int *size) > 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; > } > } > > > ------------------------------------------------------------------------------ > EMC VNX: the world's simplest storage, starting under $10K > The only unified storage solution that offers unified management > Up to 160% more powerful than alternatives and 25% more efficient. > Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev > _______________________________________________ > Libcg-devel mailing list > Libcg-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/libcg-devel > ------------------------------------------------------------------------------ EMC VNX: the world's simplest storage, starting under $10K The only unified storage solution that offers unified management Up to 160% more powerful than alternatives and 25% more efficient. Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev _______________________________________________ Libcg-devel mailing list Libcg-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libcg-devel