Browse Source

* refactor module cleanup (also fixes double-free)

master
Alex 'AdUser' Z 4 years ago
parent
commit
e202929f71
  1. 17
      src/backend.c
  2. 15
      src/filter.c
  3. 15
      src/source.c

17
src/backend.c

@ -110,11 +110,24 @@ f2b_backend_init(f2b_backend_t *backend, f2b_config_section_t *config) {
if (dlerr) if (dlerr)
f2b_log_msg(log_error, "backend load error: %s", dlerr); f2b_log_msg(log_error, "backend load error: %s", dlerr);
if (backend->h) { if (backend->h) {
if (backend->cfg && backend->destroy) if (backend->cfg && backend->destroy) {
backend->destroy(backend->cfg); backend->destroy(backend->cfg);
backend->cfg = NULL;
}
dlclose(backend->h); dlclose(backend->h);
backend->create = NULL;
backend->config = NULL;
backend->state = NULL;
backend->logcb = NULL;
backend->start = NULL;
backend->stop = NULL;
backend->ping = NULL;
backend->ban = NULL;
backend->unban = NULL;
backend->check = NULL;
backend->destroy = NULL;
backend->h = NULL;
} }
free(backend);
return false; return false;
} }

15
src/filter.c

@ -176,11 +176,22 @@ f2b_filter_init(f2b_filter_t *filter, f2b_config_section_t *config) {
if (dlerr) if (dlerr)
f2b_log_msg(log_error, "filter load error: %s", dlerr); f2b_log_msg(log_error, "filter load error: %s", dlerr);
if (filter->h) { if (filter->h) {
if (filter->cfg && filter->destroy) if (filter->cfg && filter->destroy) {
filter->destroy(filter->cfg); filter->destroy(filter->cfg);
filter->cfg = NULL;
}
dlclose(filter->h); dlclose(filter->h);
filter->create = NULL;
filter->config = NULL;
filter->append = NULL;
filter->logcb = NULL;
filter->state = NULL;
filter->flush = NULL;
filter->stats = NULL;
filter->match = NULL;
filter->destroy = NULL;
filter->h = NULL;
} }
free(filter);
return false; return false;
} }

15
src/source.c

@ -106,11 +106,22 @@ f2b_source_init(f2b_source_t *source, f2b_config_section_t *config) {
if (dlerr) if (dlerr)
f2b_log_msg(log_error, "source load error: %s", dlerr); f2b_log_msg(log_error, "source load error: %s", dlerr);
if (source->h) { if (source->h) {
if (source->cfg && source->destroy) if (source->cfg && source->destroy) {
source->destroy(source->cfg); source->destroy(source->cfg);
source->cfg = NULL;
}
dlclose(source->h); dlclose(source->h);
source->create = NULL;
source->config = NULL;
source->state = NULL;
source->logcb = NULL;
source->start = NULL;
source->next = NULL;
source->stats = NULL;
source->stop = NULL;
source->destroy = NULL;
source->h = NULL;
} }
free(source);
return false; return false;
} }

Loading…
Cancel
Save