diff --git a/Fix-memleak-in-libverto-vfree.patch b/Fix-memleak-in-libverto-vfree.patch new file mode 100644 index 0000000..91cfdf1 --- /dev/null +++ b/Fix-memleak-in-libverto-vfree.patch @@ -0,0 +1,56 @@ +From 29585309bf479fe73c3be59e2f8371c3b6c4554a Mon Sep 17 00:00:00 2001 +From: Tomas Kuthan +Date: Mon, 7 Aug 2017 16:01:43 +0200 +Subject: [PATCH] Fix memleak in libverto:vfree + +verto_set_allocator(resize, hierarchical) has an unducumented +requirement on allocator function resize, that resize(ptr, 0) is +equivalent to free(ptr). + +Some implementations of the default allocator realloc don't meet this +requirement. realloc(ptr, 0) may return a unique pointer that can be +successfully passed to free. This new pointer never gets freed and the +memory overhead leaks. + +This fix replaces realloc(ptr, 0) with free(ptr) in vresize and +documents the allocator requirement. + +[rharwood@redhat.com: Cleanup comments slightly] +Closes: #18 + +(cherry picked from commit 968d542e83619de9759ac4d8f13df30e1016b6c2) +--- + src/verto.c | 5 +++++ + src/verto.h | 3 ++- + 2 files changed, 7 insertions(+), 1 deletion(-) + +diff --git a/src/verto.c b/src/verto.c +index b98142d..da2ebc5 100644 +--- a/src/verto.c ++++ b/src/verto.c +@@ -132,6 +132,11 @@ vresize(void *mem, size_t size) + { + if (!resize_cb) + resize_cb = &realloc; ++ if (size == 0 && resize_cb == &realloc) { ++ /* Avoid memleak as realloc(X, 0) can return a free-able pointer. */ ++ free(mem); ++ return NULL; ++ } + return (*resize_cb)(mem, size); + } + +diff --git a/src/verto.h b/src/verto.h +index 15fd81e..8000d2d 100644 +--- a/src/verto.h ++++ b/src/verto.h +@@ -196,7 +196,8 @@ verto_set_default(const char *impl, verto_ev_type reqtypes); + * @see verto_add_idle() + * @see verto_add_signal() + * @see verto_add_child() +- * @param resize The allocator to use (behaves like realloc()) ++ * @param resize The allocator to use (behaves like realloc(); ++ * resize(ptr, 0) must free memory at ptr.) + * @param hierarchical Zero if the allocator is not hierarchical + */ + int diff --git a/libverto.spec b/libverto.spec index a3127e2..05a9120 100644 --- a/libverto.spec +++ b/libverto.spec @@ -2,13 +2,22 @@ Name: libverto Version: 0.2.6 -Release: 10%{?dist} +Release: 11%{?dist} Summary: Main loop abstraction library License: MIT URL: %{homepage} Source0: %{homepage}/releases/download/%{version}/%{name}-%{version}.tar.gz +Patch0: Add-Travis-support.patch +Patch1: Add-a-CI-target-for-clang.patch +Patch2: Enable-and-fix-all-warnings.patch +Patch3: Fix-memleak-in-libverto-vfree.patch + +BuildRequires: autoconf +BuildRequires: automake +BuildRequires: libtool + BuildRequires: glib2-devel BuildRequires: libevent-devel BuildRequires: libtevent-devel @@ -124,6 +133,7 @@ and signal. %autosetup -S git %build +autoreconf -fiv %configure --disable-static make %{?_smp_mflags} @@ -196,6 +206,10 @@ find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';' %endif %changelog +* Mon Aug 07 2017 Robbie Harwood - 0.2.6-11 +- Fix memleak in vfree() +- Misc spec file fixes + * Thu Aug 03 2017 Robbie Harwood - 0.2.6-10 - Fix all compile warnings