Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8cdd947 authored by Franck Bui-Huu's avatar Franck Bui-Huu Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: fix thread_map__new_by_pid_str() memory leak in error path



The namelist array (including its content) was not freed if we fail to
realloc a new 'threads' structure.

Signed-off-by: default avatarFranck Bui-Huu <fbuihuu@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1337952109-31995-1-git-send-email-fbuihuu@gmail.com


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a83eb3ea
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -188,28 +188,27 @@ static struct thread_map *thread_map__new_by_pid_str(const char *pid_str)
		nt = realloc(threads, (sizeof(*threads) +
				       sizeof(pid_t) * total_tasks));
		if (nt == NULL)
			goto out_free_threads;
			goto out_free_namelist;

		threads = nt;

		if (threads) {
			for (i = 0; i < items; i++)
		for (i = 0; i < items; i++) {
			threads->map[j++] = atoi(namelist[i]->d_name);
			threads->nr = total_tasks;
		}

		for (i = 0; i < items; i++)
			free(namelist[i]);
		}
		threads->nr = total_tasks;
		free(namelist);

		if (!threads)
			break;
	}

out:
	strlist__delete(slist);
	return threads;

out_free_namelist:
	for (i = 0; i < items; i++)
		free(namelist[i]);
	free(namelist);

out_free_threads:
	free(threads);
	threads = NULL;