mirror of
https://github.com/jarun/nnn.git
synced 2025-01-26 02:36:36 +00:00
Centralized mem free
This commit is contained in:
parent
c8f080f0b5
commit
2849da93e7
18
src/nnn.c
18
src/nnn.c
|
@ -2502,7 +2502,7 @@ static int sum_sizes(const char *fpath, const struct stat *sb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dentfree(struct entry *dents)
|
static void dentfree(void)
|
||||||
{
|
{
|
||||||
free(pnamebuf);
|
free(pnamebuf);
|
||||||
free(dents);
|
free(dents);
|
||||||
|
@ -2683,7 +2683,7 @@ static int dentfill(char *path, struct entry **dents)
|
||||||
|
|
||||||
/* Should never be null */
|
/* Should never be null */
|
||||||
if (closedir(dirp) == -1) {
|
if (closedir(dirp) == -1) {
|
||||||
dentfree(*dents);
|
dentfree();
|
||||||
errexit();
|
errexit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2883,6 +2883,8 @@ static void browse(char *ipath)
|
||||||
char *dir, *tmp;
|
char *dir, *tmp;
|
||||||
char *scriptpath = getenv(env_cfg[NNN_SCRIPT]);
|
char *scriptpath = getenv(env_cfg[NNN_SCRIPT]);
|
||||||
|
|
||||||
|
atexit(dentfree);
|
||||||
|
|
||||||
/* setup first context */
|
/* setup first context */
|
||||||
xstrlcpy(g_ctx[0].c_path, ipath, PATH_MAX); /* current directory */
|
xstrlcpy(g_ctx[0].c_path, ipath, PATH_MAX); /* current directory */
|
||||||
path = g_ctx[0].c_path;
|
path = g_ctx[0].c_path;
|
||||||
|
@ -2895,15 +2897,13 @@ static void browse(char *ipath)
|
||||||
cfg.filtermode ? (presel = FILTER) : (presel = 0);
|
cfg.filtermode ? (presel = FILTER) : (presel = 0);
|
||||||
|
|
||||||
dents = xrealloc(dents, total_dents * sizeof(struct entry));
|
dents = xrealloc(dents, total_dents * sizeof(struct entry));
|
||||||
if (dents == NULL)
|
if (!dents)
|
||||||
errexit();
|
errexit();
|
||||||
|
|
||||||
/* Allocate buffer to hold names */
|
/* Allocate buffer to hold names */
|
||||||
pnamebuf = (char *)xrealloc(pnamebuf, NAMEBUF_INCR);
|
pnamebuf = (char *)xrealloc(pnamebuf, NAMEBUF_INCR);
|
||||||
if (pnamebuf == NULL) {
|
if (!pnamebuf)
|
||||||
free(dents);
|
|
||||||
errexit();
|
errexit();
|
||||||
}
|
|
||||||
|
|
||||||
begin:
|
begin:
|
||||||
#ifdef LINUX_INOTIFY
|
#ifdef LINUX_INOTIFY
|
||||||
|
@ -3027,8 +3027,6 @@ nochange:
|
||||||
r = mkpath(path, dents[cur].name, newpath);
|
r = mkpath(path, dents[cur].name, newpath);
|
||||||
appendfpath(newpath, r);
|
appendfpath(newpath, r);
|
||||||
writecp(pcopybuf, copybufpos - 1);
|
writecp(pcopybuf, copybufpos - 1);
|
||||||
|
|
||||||
dentfree(dents);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3920,8 +3918,6 @@ nochange:
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dentfree(dents);
|
|
||||||
return;
|
return;
|
||||||
case SEL_QUITCTX:
|
case SEL_QUITCTX:
|
||||||
fd = cfg.curctx;
|
fd = cfg.curctx;
|
||||||
|
@ -3942,8 +3938,6 @@ nochange:
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
dentfree(dents);
|
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
if (xlines != LINES || xcols != COLS) {
|
if (xlines != LINES || xcols != COLS) {
|
||||||
|
|
Loading…
Reference in a new issue