0
0
mirror of https://github.com/darkk/redsocks.git synced 2025-08-30 13:45:30 +00:00

Fixed minor memory leaks during fatal failure.

This commit is contained in:
Leonid Evdokimov 2008-08-18 17:26:07 +07:00
parent 0a1bcb5bb9
commit 40fda9b6b7
2 changed files with 29 additions and 9 deletions

22
base.c
View File

@ -274,6 +274,8 @@ static parser_section base_conf_section =
/***********************************************************************
* `base` initialization
*/
static int base_fini();
static int base_init()
{
uid_t uid;
@ -385,14 +387,32 @@ static int base_init()
fail:
if (devnull != -1)
close(devnull);
base_fini();
return -1;
}
static int base_fini()
{
if (instance.redirector->fini)
instance.redirector->fini();
return -1;
free(instance.chroot);
free(instance.user);
free(instance.group);
free(instance.redirector_name);
free(instance.log_name);
memset(&instance, 0, sizeof(instance));
return 0;
}
app_subsys base_subsys =
{
.init = base_init,
.fini = base_fini,
.conf_section = &base_conf_section,
};

16
main.c
View File

@ -73,12 +73,8 @@ int main(int argc, char **argv)
FOREACH(ss, subsystems) {
if ((*ss)->init) {
error = (*ss)->init();
if (!error)
continue; // goto next subsystem
for (--ss; ss >= subsystems; ss--)
if ((*ss)->fini)
(*ss)->fini();
return EXIT_FAILURE;
if (error)
goto shutdown;
}
}
@ -86,10 +82,14 @@ int main(int argc, char **argv)
event_dispatch();
FOREACH_REV(ss, subsystems)
shutdown:
for (--ss; ss >= subsystems; ss--)
if ((*ss)->fini)
(*ss)->fini();
return EXIT_SUCCESS;
event_base_free(NULL);
return !error ? EXIT_SUCCESS : EXIT_FAILURE;
}
/* vim:set tabstop=4 softtabstop=4 shiftwidth=4: */