101 lines
2.1 KiB
Diff
101 lines
2.1 KiB
Diff
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(®ex, file, 0, NULL, 0) == 0) {
|
|
bin = assocs[i].bin;
|
|
+ regfree(®ex);
|
|
break;
|
|
}
|
|
+ regfree(®ex);
|
|
}
|
|
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
|
|
|