summaryrefslogtreecommitdiffstats
path: root/lib/libedit
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>1998-09-16 04:17:47 +0000
committerimp <imp@FreeBSD.org>1998-09-16 04:17:47 +0000
commitbfe73fd683053201c326f9ff2c8e5e0f69cc7fe7 (patch)
treeb17d45198953bfbbad4bfd632dfdf1a37b7159d2 /lib/libedit
parent68a8c771724d4fc671cac3ce95f78d4fb1874cfe (diff)
downloadFreeBSD-src-bfe73fd683053201c326f9ff2c8e5e0f69cc7fe7.zip
FreeBSD-src-bfe73fd683053201c326f9ff2c8e5e0f69cc7fe7.tar.gz
Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a = realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is guaranteed to be the same thing. I've been running these on my system here w/o ill effects for some time. However, the CTM-express is at part 6 of 34 for the CAM changes, so I've not been able to do a build world with the CAM in the tree with these changes. Shouldn't impact anything, but...
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/el.c4
-rw-r--r--lib/libedit/el.h1
-rw-r--r--lib/libedit/map.c4
-rw-r--r--lib/libedit/tokenizer.c5
4 files changed, 8 insertions, 6 deletions
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index f163ec8..c9c3f72 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -77,7 +77,7 @@ el_init(prog, fin, fout)
el->el_prog = strdup(prog);
#ifdef DEBUG
- if ((tty = getenv("DEBUGTTY")) != NULL) {
+ if (issetugid() == 0 && (tty = getenv("DEBUGTTY")) != NULL) {
el->el_errfile = fopen(tty, "w");
if (el->el_errfile == NULL) {
extern errno;
@@ -291,7 +291,7 @@ el_source(el, fname)
if (fname == NULL) {
fname = &elpath[1];
if ((fp = fopen(fname, "r")) == NULL) {
- if ((ptr = getenv("HOME")) == NULL)
+ if (issetugid() != 0 || (ptr = getenv("HOME")) == NULL)
return -1;
(void)snprintf(path, sizeof(path), "%s%s", ptr, elpath);
fname = path;
diff --git a/lib/libedit/el.h b/lib/libedit/el.h
index 77cce15..a608e20 100644
--- a/lib/libedit/el.h
+++ b/lib/libedit/el.h
@@ -86,6 +86,7 @@ typedef struct el_state_t {
*/
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
+#define el_reallocf(a,b) reallocf(a, b)
#define el_free(a) free(a)
#include "tty.h"
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index 5719827..4b940d4 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1380,9 +1380,9 @@ map_addfunc(el, name, help, func)
return -1;
el->el_map.func = (el_func_t *)
- el_realloc(el->el_map.func, nf * sizeof(el_func_t));
+ el_reallocf(el->el_map.func, nf * sizeof(el_func_t));
el->el_map.help = (el_bindings_t *)
- el_realloc(el->el_map.help, nf * sizeof(el_bindings_t));
+ el_reallocf(el->el_map.help, nf * sizeof(el_bindings_t));
nf = el->el_map.nfunc;
el->el_map.func[nf] = func;
diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c
index bbe847e..62c0249 100644
--- a/lib/libedit/tokenizer.c
+++ b/lib/libedit/tokenizer.c
@@ -59,6 +59,7 @@ typedef enum { Q_none, Q_single, Q_double, Q_one, Q_doubleone } quote_t;
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
+#define tok_reallocf(a, b) reallocf(a, b)
struct tokenizer {
@@ -377,8 +378,8 @@ tok_line(tok, line, argc, argv)
if (tok->argc >= tok->amax - 4) {
tok->amax += AINCR;
- tok->argv = (char **) tok_realloc(tok->argv,
- tok->amax * sizeof(char*));
+ tok->argv = (char **) tok_reallocf(tok->argv,
+ tok->amax * sizeof(char*));
}
}
OpenPOWER on IntegriCloud