tex: free rep and pat as soon as possible in ec_substitute() - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 8432d2bc6ab1904a6123acd8fa22738786b545af
(DIR) parent ad905f06084738d3f3a95f0775586ac515312a49
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Sun, 26 Sep 2021 18:19:08 +0330
ex: free rep and pat as soon as possible in ec_substitute()
Reported by Kyryl Melekhin <k.melekhin@gmail.com>.
Diffstat:
M ex.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/ex.c b/ex.c
t@@ -627,17 +627,15 @@ static int ec_substitute(char *loc, char *cmd, char *arg)
s--;
rep = re_read(&s);
}
- if (!rep)
- rep = uc_dup(pat ? "" : xrep);
- snprintf(xrep, sizeof(xrep), "%s", rep);
+ if (pat || rep)
+ snprintf(xrep, sizeof(xrep), "%s", rep ? rep : "");
free(pat);
+ free(rep);
if (ex_kwd(&pats[0], NULL))
return 1;
re = rset_make(1, pats, xic ? RE_ICASE : 0);
- if (!re) {
- free(rep);
+ if (!re)
return 1;
- }
for (i = beg; i < end; i++) {
char *ln = lbuf_get(xb, i);
struct sbuf *r = NULL;
t@@ -645,7 +643,7 @@ static int ec_substitute(char *loc, char *cmd, char *arg)
if (!r)
r = sbuf_make();
sbuf_mem(r, ln, offs[0]);
- replace(r, rep, ln, offs);
+ replace(r, xrep, ln, offs);
ln += offs[1];
if (!*ln || !strchr(s, 'g'))
break;
t@@ -659,7 +657,6 @@ static int ec_substitute(char *loc, char *cmd, char *arg)
}
}
rset_free(re);
- free(rep);
return 0;
}
t@@ -693,7 +690,7 @@ static int ec_exec(char *loc, char *cmd, char *arg)
return 0;
}
-static int ec_make(char *log, char *cmd, char *arg)
+static int ec_make(char *loc, char *cmd, char *arg)
{
char make[EXLEN];
char *target;