From 8509afb20852a2971068b6040059c948dd7464a2 Mon Sep 17 00:00:00 2001 From: lingsheng <860373352@qq.com> Date: Tue, 30 Jul 2024 08:44:51 +0000 Subject: [PATCH] XcursorXcFileLoad: plug memory leak in error paths --- ...Load-plug-memory-leak-in-error-paths.patch | 42 +++++++++++++++++++ libXcursor.spec | 7 +++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 backport-XcursorXcFileLoad-plug-memory-leak-in-error-paths.patch diff --git a/backport-XcursorXcFileLoad-plug-memory-leak-in-error-paths.patch b/backport-XcursorXcFileLoad-plug-memory-leak-in-error-paths.patch new file mode 100644 index 0000000..35799e6 --- /dev/null +++ b/backport-XcursorXcFileLoad-plug-memory-leak-in-error-paths.patch @@ -0,0 +1,42 @@ +From 5e0f8347cebef2b3a9f5d75ca254aabaa0bca259 Mon Sep 17 00:00:00 2001 +From: Alan Coopersmith +Date: Sun, 8 Oct 2023 10:48:25 -0700 +Subject: [PATCH] XcursorXcFileLoad: plug memory leak in error paths +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Found by gcc analyzer: +file.c: In function ‘XcursorXcFileLoad’: +file.c:782:8: warning: leak of ‘fileHeader’ [CWE-401] [-Wanalyzer-malloc-leak] + 782 | if (!images) + | ^ + +Fixes: 3b84b14 ("Initial revision") +Signed-off-by: Alan Coopersmith +--- + src/file.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/file.c b/src/file.c +index 0e26955..496d447 100644 +--- a/src/file.c ++++ b/src/file.c +@@ -780,10 +780,14 @@ XcursorXcFileLoad (XcursorFile *file, + } + images = XcursorImagesCreate (nimage); + if (!images) ++ { ++ _XcursorFileHeaderDestroy (fileHeader); + return 0; ++ } + comments = XcursorCommentsCreate (ncomment); + if (!comments) + { ++ _XcursorFileHeaderDestroy (fileHeader); + XcursorImagesDestroy (images); + return 0; + } +-- +2.33.0 + diff --git a/libXcursor.spec b/libXcursor.spec index 370d754..ba5a736 100644 --- a/libXcursor.spec +++ b/libXcursor.spec @@ -3,12 +3,14 @@ Name: libXcursor Summary: Cursor management library Version: 1.2.1 -Release: 1 +Release: 2 License: MIT URL: https://xorg.freedesktop.org/ Source0: https://xorg.freedesktop.org/archive/individual/lib/%{name}-%{version}.tar.gz Source1: index.theme +Patch0: backport-XcursorXcFileLoad-plug-memory-leak-in-error-paths.patch + Requires: libX11 BuildRequires: xorg-x11-proto-devel libX11-devel BuildRequires: autoconf automake libtool xorg-x11-util-macros @@ -68,6 +70,9 @@ install -m644 %{SOURCE1} $RPM_BUILD_ROOT%{_datadir}/icons/default/index.theme %{_mandir}/man3/Xcursor*.3* %changelog +* Tue Jul 30 2024 lingsheng - 1.2.1-2 +- XcursorXcFileLoad: plug memory leak in error paths + * Mon Aug 1 2022 tianlijing - 1.2.1-1 - update to 1.2.1