[PATCH v2] perf probe: Fix an error handling path in 'parse_perf_probe_command()'

Christophe JAILLET posted 1 patch 3 years, 8 months ago
tools/perf/util/probe-event.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH v2] perf probe: Fix an error handling path in 'parse_perf_probe_command()'
Posted by Christophe JAILLET 3 years, 8 months ago
If a memory allocation fail, we should branch to the error handling path in
order to free some resources allocated a few lines above.

Fixes: 15354d546986 ("perf probe: Generate event name with line number")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
---
Change in v2:
 - Synch with latest -next
 - Add A-by tag (see link below, it was old!)

v1:
 https://lore.kernel.org/all/20200315201259.29190-1-christophe.jaillet@wanadoo.fr/
---
 tools/perf/util/probe-event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 67c12d5303e7..785246ff4179 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -1775,8 +1775,10 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
 	if (!pev->event && pev->point.function && pev->point.line
 			&& !pev->point.lazy_line && !pev->point.offset) {
 		if (asprintf(&pev->event, "%s_L%d", pev->point.function,
-			pev->point.line) < 0)
-			return -ENOMEM;
+			pev->point.line) < 0) {
+			ret = -ENOMEM;
+			goto out;
+		}
 	}
 
 	/* Copy arguments and ensure return probe has no C argument */
-- 
2.34.1
Re: [PATCH v2] perf probe: Fix an error handling path in 'parse_perf_probe_command()'
Posted by Arnaldo Carvalho de Melo 3 years, 8 months ago
Em Sat, Aug 06, 2022 at 04:51:26PM +0200, Christophe JAILLET escreveu:
> If a memory allocation fail, we should branch to the error handling path in
> order to free some resources allocated a few lines above.
> 
> Fixes: 15354d546986 ("perf probe: Generate event name with line number")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>


Thanks, applied.

- Arnaldo


> ---
> Change in v2:
>  - Synch with latest -next
>  - Add A-by tag (see link below, it was old!)
> 
> v1:
>  https://lore.kernel.org/all/20200315201259.29190-1-christophe.jaillet@wanadoo.fr/
> ---
>  tools/perf/util/probe-event.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 67c12d5303e7..785246ff4179 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -1775,8 +1775,10 @@ int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
>  	if (!pev->event && pev->point.function && pev->point.line
>  			&& !pev->point.lazy_line && !pev->point.offset) {
>  		if (asprintf(&pev->event, "%s_L%d", pev->point.function,
> -			pev->point.line) < 0)
> -			return -ENOMEM;
> +			pev->point.line) < 0) {
> +			ret = -ENOMEM;
> +			goto out;
> +		}
>  	}
>  
>  	/* Copy arguments and ensure return probe has no C argument */
> -- 
> 2.34.1

-- 

- Arnaldo