Re: [Powertop] [PATCH 2/2] perf: Check return value of strdup

Chris Ferron <chris.e.ferron at linux.intel.com> Mon, 17 Sep 2012 08:21:15 -0700
Newsgroups dev.linux.lists.powertop
Message-ID <[email protected]>
On 09/16/2012 07:17 AM, Namhyung Kim wrote:
> The strdup() can return NULL so that the result should be checked.
>
> Signed-off-by: Namhyung Kim <namhyung(a)gmail.com>
> ---
>   src/perf/perf.cpp |    5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/src/perf/perf.cpp b/src/perf/perf.cpp
> index c8ba7a8..35b4017 100644
> --- a/src/perf/perf.cpp
> +++ b/src/perf/perf.cpp
> @@ -145,6 +145,11 @@ void perf_event::set_event_name(const char *event_name)
>   	if (name)
>   		free(name);
>   	name = strdup(event_name);
> +	if (!name) {
> +		fprintf(stderr, "failed to allocate event name\n");
> +		return;
> +	}
> +
>   	char *c;
>   
>   	c = strchr(name, ':');
Your patch as been merged.
Thank You
-C