From patchwork Tue Jul 14 21:19:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 11663815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E5A417C5 for ; Tue, 14 Jul 2020 21:23:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6598220658 for ; Tue, 14 Jul 2020 21:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728277AbgGNVXW (ORCPT ); Tue, 14 Jul 2020 17:23:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:60714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728155AbgGNVXV (ORCPT ); Tue, 14 Jul 2020 17:23:21 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6FA4A2071B; Tue, 14 Jul 2020 21:23:21 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.93) (envelope-from ) id 1jvSOW-004vZ8-Em; Tue, 14 Jul 2020 17:23:20 -0400 Message-ID: <20200714212320.335487573@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 14 Jul 2020 17:19:33 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Cc: Namhyung Kim , "Tzvetomir Stoyanov (VMware)" Subject: [PATCH 4/8] libtraceevent: Improve error handling of tep_plugin_add_option() API References: <20200714211929.828530560@goodmis.org> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Tzvetomir Stoyanov (VMware)" In case of memory error, ensure all allocated resources are freed. Do not append broken option in trace_plugin_options list. Link: https://lore.kernel.org/r/CAM9d7cizjF+fbK7YzmsBDgrx__4YAOsmEq67D3sWET8FF+YdFA@mail.gmail.com Link: https://lore.kernel.org/linux-trace-devel/20200714103027.2477584-5-tz.stoyanov@gmail.com Suggested-by: Namhyung Kim Acked-by: Namhyung Kim Signed-off-by: Tzvetomir Stoyanov (VMware) Signed-off-by: Steven Rostedt (VMware) --- lib/traceevent/event-plugin.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c index 03f26c8c58d5..aa868133cbdf 100644 --- a/lib/traceevent/event-plugin.c +++ b/lib/traceevent/event-plugin.c @@ -361,23 +361,25 @@ int tep_plugin_add_option(const char *name, const char *val) if (!op) { op = malloc(sizeof(*op)); if (!op) - return -ENOMEM; + goto out_free; memset(op, 0, sizeof(*op)); - op->next = trace_plugin_options; - trace_plugin_options = op; - op->plugin = plugin; op->option = option_str; - if (val) { op->value = strdup(val); - if (!op->value) + if (!op->value) { + free(op); goto out_free; + } } + op->next = trace_plugin_options; + trace_plugin_options = op; } return process_option(plugin, option_str, val); - out_free: + +out_free: + free(plugin); free(option_str); return -ENOMEM; }