From patchwork Sun Jan 28 19:38:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin ROBIN X-Patchwork-Id: 13534617 Received: from smtpout1.mo529.mail-out.ovh.net (smtpout1.mo529.mail-out.ovh.net [178.32.125.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E8653C46B for ; Sun, 28 Jan 2024 19:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.32.125.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470699; cv=none; b=uf2W3229jbtSkVJn1T+g/lWZG4IeUUqqr4b5nGsKWCkoRks4kvGo9q4lMaQk0u4M9019FLlgXU6E/93fePu8psRpcRGTRVi99U3VF3y2IP7xOsNR9IzcVRB3AmVT0qneIztrSJJY2V8N34nq7O7P2tS4NyIQ0oY8Nq66r3NIsqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706470699; c=relaxed/simple; bh=mAW7JUFqK2/DB5MRz7n/y2rVGWSLQRkMEPR+C7cNbTo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Hyj+xuZt0fzjW0QOFj8dE1DLCs+qLpFmGS8Tewul44uDrj5p/eU9pYgO+1LUgjqk9zd/b+ebGXX3KL2de799i1FlZTbZuxkHkLtIrTlshQLvWDH5aN2bS1oL1yEJJ8cmCI2I+4wlpKYp5nf9E8clBw3ukA1Ai0JCiZQFkfFGjCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr; spf=pass smtp.mailfrom=benjarobin.fr; arc=none smtp.client-ip=178.32.125.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=benjarobin.fr Received: from mxplan5.mail.ovh.net (unknown [10.108.2.104]) by mo529.mail-out.ovh.net (Postfix) with ESMTPS id 5313520405; Sun, 28 Jan 2024 19:38:14 +0000 (UTC) Received: from benjarobin.fr (37.59.142.106) by DAG6EX2.mxp5.local (172.16.2.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 28 Jan 2024 20:38:13 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-106R00613c29725-0ab7-44c3-9eb2-65e619e37cb8, F6BBF12166BF17D31185B0BF3C367C102A143481) smtp.auth=dev@benjarobin.fr X-OVh-ClientIp: 92.161.126.4 From: Benjamin ROBIN To: CC: , Benjamin ROBIN Subject: [PATCH v2 05/34] kernelshark: Prevent potential detach of QMap container Date: Sun, 28 Jan 2024 20:38:04 +0100 Message-ID: <20240128193804.58113-1-dev@benjarobin.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: <8e64baa3-e08a-81d9-bcf6-2876859b7a6e@gmail.com> References: <8e64baa3-e08a-81d9-bcf6-2876859b7a6e@gmail.com> Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: DAG4EX1.mxp5.local (172.16.2.31) To DAG6EX2.mxp5.local (172.16.2.52) X-Ovh-Tracer-GUID: bf09453a-52b3-4b1b-9c48-d5f385d87872 X-Ovh-Tracer-Id: 12476659820109586330 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtvddguddviecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomhepuegvnhhjrghmihhnucftqfeukffpuceouggvvhessggvnhhjrghrohgsihhnrdhfrheqnecuggftrfgrthhtvghrnheptdehteffieekvdejgeduleehleekheehkefggfehhedtveejffejvdegtdevhfejnecukfhppeduvdejrddtrddtrddupdefjedrheelrddugedvrddutdeipdelvddrudeiuddruddviedrgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoeguvghvsegsvghnjhgrrhhosghinhdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeihrdhkrghrrgguiiesghhmrghilhdrtghomhdplhhinhhugidqthhrrggtvgdquggvvhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhohedvledpmhhouggvpehsmhhtphhouhht Use const_iterator instead. Fix range-loop-detach Clazy warning. Indeed when using C++11 range-loops, the .begin() and .end() functions are called, instead of .cbegin() and .cend(). This imply before looping over the QMap, it may perform a deep-copy of it (if shared). See also the explanation given by Qt documentation of qAsConst(). Another solution is to use "std::as_const" cast on the QMap object. Signed-off-by: Benjamin ROBIN --- src/KsGLWidget.cpp | 5 +++-- src/plugins/KVMComboDialog.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/KsGLWidget.cpp b/src/KsGLWidget.cpp index 9e3dac3..0a44e77 100644 --- a/src/KsGLWidget.cpp +++ b/src/KsGLWidget.cpp @@ -137,9 +137,10 @@ void KsGLWidget::paintGL() /* Draw the time axis. */ _drawAxisX(size); - for (auto const &stream: _graphs) - for (auto const &g: stream) + for (auto it = _graphs.cbegin(), end = _graphs.cend(); it != end; ++it) { + for (auto const &g: it.value()) g->draw(size); + } for (auto const &s: _shapes) { if (!s) diff --git a/src/plugins/KVMComboDialog.cpp b/src/plugins/KVMComboDialog.cpp index 2b95a53..6be68d4 100644 --- a/src/plugins/KVMComboDialog.cpp +++ b/src/plugins/KVMComboDialog.cpp @@ -308,13 +308,15 @@ void KsComboPlotDialog::_applyPress() int nPlots(0); _plotMap[guestId] = _streamCombos(guestId); - for (auto const &stream: _plotMap) - for (auto const &combo: stream) { + + for (auto it = _plotMap.cbegin(), end = _plotMap.cend(); it != end; ++it) { + for (auto const &combo: it.value()) { allCombosVec.append(2); combo[0] >> allCombosVec; combo[1] >> allCombosVec; ++nPlots; } + } emit apply(nPlots, allCombosVec); } From patchwork Sun Jan 28 19:26:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin ROBIN X-Patchwork-Id: 13534603 Received: from smtpout1.mo529.mail-out.ovh.net (smtpout1.mo529.mail-out.ovh.net [178.32.125.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A514E31A82 for ; Sun, 28 Jan 2024 19:26:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.32.125.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469986; cv=none; b=bqKTKvMZVXzs3PP3E6L3hVVG3OevrOQOgkJcxX9kgYhJ+6cJXonCOxJ/iRS4rAOsnUcSJZ0rj/DdhRPRXszN3jwm/SKGteuR7eLbb7vbff3sWoFENwJUO23QTR13+oaiimyxtvCjfWwTq2gf7WQrXZ91KoOJE2Qnp8oPvJt3PjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469986; c=relaxed/simple; bh=b2BDqdOLKlFpbBEKxJWAsTDNfOSB7v9ZmSM5vAp0Qx8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RvUknH/CGFB1cYLlbTw1zopj5zWzRn/KDJLFQBid7kRj5VkDbujsAccCguj8iWD9hGdTRIde6xRQESAb3ONEfxKDOx4hs/DkpEEH7hxIT8Gy/7eMWFY2LpgMmKydTYOz2WXhK57HteX5OyweW34HU0JDQEIP1p4iAgw47psJHAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr; spf=pass smtp.mailfrom=benjarobin.fr; arc=none smtp.client-ip=178.32.125.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=benjarobin.fr Received: from mxplan5.mail.ovh.net (unknown [10.109.140.93]) by mo529.mail-out.ovh.net (Postfix) with ESMTPS id C33A52044F; Sun, 28 Jan 2024 19:26:21 +0000 (UTC) Received: from benjarobin.fr (37.59.142.106) by DAG6EX2.mxp5.local (172.16.2.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 28 Jan 2024 20:26:21 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-106R00662ac2f67-aa6c-41af-bf85-352244ba7130, F6BBF12166BF17D31185B0BF3C367C102A143481) smtp.auth=dev@benjarobin.fr X-OVh-ClientIp: 92.161.126.4 From: Benjamin ROBIN To: CC: , Benjamin ROBIN Subject: [PATCH v2 11/34] kernelshark: Prevent potential divide by zero in Shape::center() Date: Sun, 28 Jan 2024 20:26:14 +0100 Message-ID: <20240128192614.56399-1-dev@benjarobin.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: DAG7EX1.mxp5.local (172.16.2.61) To DAG6EX2.mxp5.local (172.16.2.52) X-Ovh-Tracer-GUID: a42ef0c5-9623-46fc-b72f-2185a2c97ce6 X-Ovh-Tracer-Id: 12275968162557747098 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtvddguddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomhepuegvnhhjrghmihhnucftqfeukffpuceouggvvhessggvnhhjrghrohgsihhnrdhfrheqnecuggftrfgrthhtvghrnheptdehteffieekvdejgeduleehleekheehkefggfehhedtveejffejvdegtdevhfejnecukfhppeduvdejrddtrddtrddupdefjedrheelrddugedvrddutdeipdelvddrudeiuddruddviedrgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoeguvghvsegsvghnjhgrrhhosghinhdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeihrdhkrghrrgguiiesghhmrghilhdrtghomhdplhhinhhugidqthhrrggtvgdquggvvhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhohedvledpmhhouggvpehsmhhtphhouhht Signed-off-by: Benjamin ROBIN --- src/KsPlotTools.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/KsPlotTools.cpp b/src/KsPlotTools.cpp index 1d63a9b..f362eaa 100644 --- a/src/KsPlotTools.cpp +++ b/src/KsPlotTools.cpp @@ -318,6 +318,9 @@ ksplot_point Shape::center() const { ksplot_point c = {0, 0}; + if (_nPoints == 0) + return c; + for (size_t i = 0; i < _nPoints; ++i) { c.x += _points[i].x; c.y += _points[i].y; From patchwork Sun Jan 28 19:25:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin ROBIN X-Patchwork-Id: 13534602 Received: from 2.mo548.mail-out.ovh.net (2.mo548.mail-out.ovh.net [178.33.255.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C65132E401 for ; Sun, 28 Jan 2024 19:25:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.33.255.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469955; cv=none; b=ginB+m0+d4KWC6bc3P3A4xkeyZw1A/VX1Y2jkFdWerVwsh1MQo2V8N61Y6yUP+87z4UCopxQ+Le2dodsRQsmsrEP2bMl70n29cEWsgPBT5/YI0l/by37UM7naeiLG8xAIZmECMS+ixpIbjcaoTPZGB8HpM556MNP/Fs9yT9COlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469955; c=relaxed/simple; bh=+sTxfy8pSylwvtWNBeJPiw3AfQcwIVJ5cvPWCRqdqy0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dtIj3114olIDgda5GnMTJbVBPKbiHpqt9jPMBkftGbTT2ctFNqbtIb6VOlL2HT2IXl4bek8C3heEDKLOAR6RKSEnuIZnRRlrox5VB9mPCEmHRHUEHK8lKyu/GcolNvh6uiSkZDZUaNsRhR9fVaJyfhn7jd25MShGC0GXIdXSnXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr; spf=pass smtp.mailfrom=benjarobin.fr; arc=none smtp.client-ip=178.33.255.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=benjarobin.fr Received: from mxplan5.mail.ovh.net (unknown [10.109.139.22]) by mo548.mail-out.ovh.net (Postfix) with ESMTPS id BA1FB21476; Sun, 28 Jan 2024 19:25:50 +0000 (UTC) Received: from benjarobin.fr (37.59.142.107) by DAG6EX2.mxp5.local (172.16.2.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 28 Jan 2024 20:25:50 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-107S001e2502754-dc9d-49bf-a1be-6e198acd4542, F6BBF12166BF17D31185B0BF3C367C102A143481) smtp.auth=dev@benjarobin.fr X-OVh-ClientIp: 92.161.126.4 From: Benjamin ROBIN To: CC: , Benjamin ROBIN Subject: [PATCH v2 20/34] kernelshark: Fix potential memory leaks in libkshark-configio Date: Sun, 28 Jan 2024 20:25:39 +0100 Message-ID: <20240128192539.56331-1-dev@benjarobin.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: DAG8EX2.mxp5.local (172.16.2.72) To DAG6EX2.mxp5.local (172.16.2.52) X-Ovh-Tracer-GUID: 50924710-8f80-401f-ad0c-cd819b7c81ce X-Ovh-Tracer-Id: 12267242436884258714 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtvddguddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomhepuegvnhhjrghmihhnucftqfeukffpuceouggvvhessggvnhhjrghrohgsihhnrdhfrheqnecuggftrfgrthhtvghrnheptdehteffieekvdejgeduleehleekheehkefggfehhedtveejffejvdegtdevhfejnecukfhppeduvdejrddtrddtrddupdefjedrheelrddugedvrddutdejpdelvddrudeiuddruddviedrgeenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoeguvghvsegsvghnjhgrrhhosghinhdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeihrdhkrghrrgguiiesghhmrghilhdrtghomhdplhhinhhugidqthhrrggtvgdquggvvhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheegkedpmhhouggvpehsmhhtphhouhht Free previously allocated kshark_config_doc if format is not supported. Also allow to call kshark_export_*() functions that allocate a new kshark_config_doc with format equal to KS_CONFIG_AUTO. Signed-off-by: Benjamin ROBIN --- src/libkshark-configio.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libkshark-configio.c b/src/libkshark-configio.c index 9a1ba60..3a0e979 100644 --- a/src/libkshark-configio.c +++ b/src/libkshark-configio.c @@ -515,7 +515,7 @@ kshark_export_trace_file(const char *file, const char *name, if (!conf) return NULL; - switch (format) { + switch (conf->format) { case KS_CONFIG_JSON: kshark_trace_file_to_json(file, name, conf->conf_doc); return conf; @@ -523,6 +523,7 @@ kshark_export_trace_file(const char *file, const char *name, default: fprintf(stderr, "Document format %d not supported\n", conf->format); + kshark_free_config_doc(conf); return NULL; } } @@ -682,7 +683,7 @@ kshark_export_plugin_file(struct kshark_plugin_list *plugin, if (!conf) return NULL; - switch (format) { + switch (conf->format) { case KS_CONFIG_JSON: kshark_plugin_to_json(plugin, conf->conf_doc); return conf; @@ -690,6 +691,7 @@ kshark_export_plugin_file(struct kshark_plugin_list *plugin, default: fprintf(stderr, "Document format %d not supported\n", conf->format); + kshark_free_config_doc(conf); return NULL; } } @@ -740,12 +742,12 @@ kshark_export_all_plugins(struct kshark_context *kshark_ctx, enum kshark_config_formats format) { struct kshark_config_doc *conf = - kshark_config_new("kshark.config.plugins", KS_CONFIG_JSON); + kshark_config_new("kshark.config.plugins", format); if (!conf) return NULL; - switch (format) { + switch (conf->format) { case KS_CONFIG_JSON: kshark_all_plugins_to_json(kshark_ctx, conf->conf_doc); return conf; @@ -753,6 +755,7 @@ kshark_export_all_plugins(struct kshark_context *kshark_ctx, default: fprintf(stderr, "Document format %d not supported\n", conf->format); + kshark_free_config_doc(conf); return NULL; } } @@ -868,12 +871,12 @@ kshark_export_stream_plugins(struct kshark_data_stream *stream, enum kshark_config_formats format) { struct kshark_config_doc *conf = - kshark_config_new("kshark.config.plugins", KS_CONFIG_JSON); + kshark_config_new("kshark.config.plugins", format); if (!conf) return NULL; - switch (format) { + switch (conf->format) { case KS_CONFIG_JSON: kshark_stream_plugins_to_json(stream, conf->conf_doc); return conf; @@ -881,6 +884,7 @@ kshark_export_stream_plugins(struct kshark_data_stream *stream, default: fprintf(stderr, "Document format %d not supported\n", conf->format); + kshark_free_config_doc(conf); return NULL; } } @@ -1026,14 +1030,15 @@ kshark_export_model(struct kshark_trace_histo *histo, if (!conf) return NULL; - switch (format) { + switch (conf->format) { case KS_CONFIG_JSON: kshark_model_to_json(histo, conf->conf_doc); return conf; default: fprintf(stderr, "Document format %d not supported\n", - format); + conf->format); + kshark_free_config_doc(conf); return NULL; } } From patchwork Sun Jan 28 19:24:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin ROBIN X-Patchwork-Id: 13534601 Received: from 7.mo548.mail-out.ovh.net (7.mo548.mail-out.ovh.net [46.105.33.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 212C431A66 for ; Sun, 28 Jan 2024 19:25:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.105.33.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469925; cv=none; b=mD1C1wLlqNBLitcogQMOzdIPDrvn28Vs2MMErxRiF8b06ZVG47WRFqnjDZzSmA9wEvjn9/HjbNNPv0HJKQNTQmx2/5Ob3MfcOlJJeK9cc39j9eayZ3I5OWbzpD43kzL2cvIgvHZWFkyW3vLMfAf4cWAvv66OMEMYPutiW5+ZGqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706469925; c=relaxed/simple; bh=yGwtjRQqpxrE0whNNQG7J08GSxIkD078+tGMYA9uKmg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cPBQjSZtGLVjZ9KGRQuSO6gTLzBly3nfJGwnFgLhumuzho7OgF2YSp6ppqTg+QM7TyvXOJKra8XVIu3k9aRrfk+IA+Mg4f7j2eP6d1c96DkejojCGiLIqgU0gOtJTCqm6BUUScPKM/669L4YNnB79DerxFcQ4+h6mhjU4EPH8vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr; spf=pass smtp.mailfrom=benjarobin.fr; arc=none smtp.client-ip=46.105.33.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=benjarobin.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=benjarobin.fr Received: from mxplan5.mail.ovh.net (unknown [10.108.17.171]) by mo548.mail-out.ovh.net (Postfix) with ESMTPS id 6B7DA20F31; Sun, 28 Jan 2024 19:25:13 +0000 (UTC) Received: from benjarobin.fr (37.59.142.97) by DAG6EX2.mxp5.local (172.16.2.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 28 Jan 2024 20:25:12 +0100 Authentication-Results: garm.ovh; auth=pass (GARM-97G002aba63841-86cf-4a2a-bd4f-cfa9e7db7622, F6BBF12166BF17D31185B0BF3C367C102A143481) smtp.auth=dev@benjarobin.fr X-OVh-ClientIp: 92.161.126.4 From: Benjamin ROBIN To: CC: , Benjamin ROBIN Subject: [PATCH v2 24/34] kernelshark: Fix potential memory leaks in libkshark-tepdata Date: Sun, 28 Jan 2024 20:24:59 +0100 Message-ID: <20240128192459.56260-1-dev@benjarobin.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: DAG4EX2.mxp5.local (172.16.2.32) To DAG6EX2.mxp5.local (172.16.2.52) X-Ovh-Tracer-GUID: f149111e-baa7-4243-b590-c3726da01ea1 X-Ovh-Tracer-Id: 12256827863587119002 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrfedtvddguddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfgtihesthekredtredttdenucfhrhhomhepuegvnhhjrghmihhnucftqfeukffpuceouggvvhessggvnhhjrghrohgsihhnrdhfrheqnecuggftrfgrthhtvghrnheptdehteffieekvdejgeduleehleekheehkefggfehhedtveejffejvdegtdevhfejnecukfhppeduvdejrddtrddtrddupdefjedrheelrddugedvrdeljedpledvrdduiedurdduvdeirdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeouggvvhessggvnhhjrghrohgsihhnrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohephidrkhgrrhgrugiisehgmhgrihhlrdgtohhmpdhlihhnuhigqdhtrhgrtggvqdguvghvvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehgeekpdhmohguvgepshhmthhpohhuth - In tepdata_get_field_names(), buffer was never free on error - In kshark_tep_open_buffer(), names were never free if kshark_get_data_stream() failed - In kshark_tep_open_buffer(), prevent any double free error with "name" and "file" fields of buffer_stream - In kshark_tep_init_all_buffers(), return failure code if failed to copy "name" and "file" fields of buffer_stream Signed-off-by: Benjamin ROBIN --- src/libkshark-tepdata.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c index 2d0fcb0..ea647f9 100644 --- a/src/libkshark-tepdata.c +++ b/src/libkshark-tepdata.c @@ -949,6 +949,7 @@ static int tepdata_get_field_names(struct kshark_data_stream *stream, for (i = 0; i < nr_fields; ++i) free(buffer[i]); + free(buffer); return -EFAULT; } @@ -1424,8 +1425,10 @@ int kshark_tep_open_buffer(struct kshark_context *kshark_ctx, int sd, sd_buffer = kshark_add_stream(kshark_ctx); buffer_stream = kshark_get_data_stream(kshark_ctx, sd_buffer); - if (!buffer_stream) - return -EFAULT; + if (!buffer_stream) { + ret = -EFAULT; + goto end; + } for (i = 0; i < n_buffers; ++i) { if (strcmp(buffer_name, names[i]) == 0) { @@ -1438,7 +1441,8 @@ int kshark_tep_open_buffer(struct kshark_context *kshark_ctx, int sd, if (!buffer_stream->name || !buffer_stream->file) { free(buffer_stream->name); free(buffer_stream->file); - + buffer_stream->name = NULL; + buffer_stream->file = NULL; ret = -ENOMEM; break; } @@ -1449,6 +1453,7 @@ int kshark_tep_open_buffer(struct kshark_context *kshark_ctx, int sd, } } +end: for (i = 0; i < n_buffers; ++i) free(names[i]); free(names); @@ -1500,8 +1505,9 @@ int kshark_tep_init_all_buffers(struct kshark_context *kshark_ctx, if (!buffer_stream->name || !buffer_stream->file) { free(buffer_stream->name); free(buffer_stream->file); - ret = -ENOMEM; - break; + buffer_stream->name = NULL; + buffer_stream->file = NULL; + return -ENOMEM; } ret = kshark_tep_stream_init(buffer_stream, buffer_input);