env.c: free memory at exit.
Make sure the memory for the 'base' string is always free'd when the program exits.
This commit is contained in:
parent
b65c9e74aa
commit
107aae0105
1 changed files with 7 additions and 0 deletions
7
env.c
7
env.c
|
|
@ -29,6 +29,12 @@
|
||||||
|
|
||||||
static char *base = NULL;
|
static char *base = NULL;
|
||||||
|
|
||||||
|
static void free_base() {
|
||||||
|
|
||||||
|
if (base)
|
||||||
|
free(base);
|
||||||
|
}
|
||||||
|
|
||||||
static void get_base() {
|
static void get_base() {
|
||||||
|
|
||||||
struct buffer buf = BUFFER_INIT;
|
struct buffer buf = BUFFER_INIT;
|
||||||
|
|
@ -40,6 +46,7 @@ static void get_base() {
|
||||||
buffer_append_str(&buf, "/.dlight");
|
buffer_append_str(&buf, "/.dlight");
|
||||||
|
|
||||||
base = buffer_cstr_release(&buf);
|
base = buffer_cstr_release(&buf);
|
||||||
|
atexit(free_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* env_get_dir() {
|
const char* env_get_dir() {
|
||||||
|
|
|
||||||
Reference in a new issue