noice: fix regex memory leak

This commit is contained in:
Nathan Owens 2019-01-01 06:54:41 -06:00 committed by maxice8
parent 3eea5ecde9
commit 34919f4cb2
2 changed files with 102 additions and 2 deletions

View file

@ -0,0 +1,100 @@
From 7136d6b548055cdb9ce9d9aa5f5f12c9d6e6ead5 Mon Sep 17 00:00:00 2001
From: Nathan Owens <ndowens04@gmail.com>
Date: Tue, 1 Jan 2019 06:46:10 -0600
Subject: [PATCH] Fix regex memory leak
---
noice.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git noice.c noice.c
index 2dc895d..8bc57de 100644
--- noice.c
+++ noice.c
@@ -38,6 +38,7 @@
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define ISODD(x) ((x) & 1)
#define CONTROL(c) ((c) ^ 0x40)
+#define META(c) ((c) ^ 0x80)
struct assoc {
char *regex; /* Regex to match on filename */
@@ -213,8 +214,10 @@ openwith(char *file)
continue;
if (regexec(&regex, file, 0, NULL, 0) == 0) {
bin = assocs[i].bin;
+ regfree(&regex);
break;
}
+ regfree(&regex);
}
DPRINTF_S(bin);
return bin;
@@ -238,6 +241,12 @@ setfilter(regex_t *regex, char *filter)
return r;
}
+void
+freefilter(regex_t *regex)
+{
+ regfree(regex);
+}
+
void
initfilter(int dot, char **ifilter)
{
@@ -327,18 +336,28 @@ printprompt(char *str)
printw(str);
}
-/* Returns SEL_* if key is bound and 0 otherwise.
- * Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}) */
-int
-nextsel(char **run, char **env)
+int xgetch(void)
{
- int c, i;
+ int c;
c = getch();
if (c == -1)
idle++;
else
idle = 0;
+ return c;
+}
+
+/* Returns SEL_* if key is bound and 0 otherwise.
+ * Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}) */
+int
+nextsel(char **run, char **env)
+{
+ int c, i;
+
+ c = xgetch();
+ if (c == 033)
+ c = META(xgetch());
for (i = 0; i < LEN(bindings); i++)
if (c == bindings[i].sym) {
@@ -520,6 +539,9 @@ populate(char *path, char *oldpath, char *fltr)
dents = NULL;
ndents = dentfill(path, &dents, visible, &re);
+ freefilter(&re);
+ if (ndents == 0)
+ return 0; /* Empty result */
qsort(dents, ndents, sizeof(*dents), entrycmp);
@@ -677,6 +699,7 @@ nochange:
r = setfilter(&re, tmp);
if (r != 0)
goto nochange;
+ freefilter(&re);
strlcpy(fltr, tmp, sizeof(fltr));
DPRINTF_S(fltr);
/* Save current */
--
2.20.1

View file

@ -1,13 +1,13 @@
# Template file for 'noice'
pkgname=noice
version=0.6
revision=2
revision=3
build_style=gnu-makefile
make_install_args="MANPREFIX=/usr/share/man"
makedepends="ncurses-devel"
short_desc="Small file browser"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
license="BSD"
license="BSD-2-Clause"
homepage="http://git.2f30.org/noice"
distfiles="http://dl.2f30.org/releases/${pkgname}-${version}.tar.gz"
checksum=1996e71dd309f83bd2f892b996fa0c2c481949d2e3dd49e4f7649a1fce5ab351