From a1ec9ec5db926037697c458b438a002d946b8b27 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Mon, 19 Nov 2012 11:55:38 +0100 Subject: [PATCH] light: fix memory leak in rot destruction --- sy_old/mars_light.c | 35 ++++++++++++++--------------------- sy_old/strategy.h | 1 + sy_old/sy_generic.c | 3 +++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/sy_old/mars_light.c b/sy_old/mars_light.c index 20148df2..77b87d1b 100644 --- a/sy_old/mars_light.c +++ b/sy_old/mars_light.c @@ -1305,26 +1305,6 @@ int kill_any(void *buf, struct mars_dent *dent) return 1; } -static -int kill_log(void *buf, struct mars_dent *dent) -{ - struct mars_global *global = buf; - struct mars_rotate *rot = dent->d_private; - - if (global->global_power.button || !is_shutdown()) { - return 0; - } - - if (likely(rot)) { - brick_string_free(rot->copy_path); - brick_string_free(rot->parent_path); - rot->copy_path = NULL; - rot->parent_path = NULL; - } - - return kill_any(buf, dent); -} - /////////////////////////////////////////////////////////////////////// // handlers / helpers for logfile rotation @@ -1683,6 +1663,18 @@ out: return status; } +static +void rot_destruct(void *_rot) +{ + struct mars_rotate *rot = _rot; + if (likely(rot)) { + brick_string_free(rot->copy_path); + brick_string_free(rot->parent_path); + rot->copy_path = NULL; + rot->parent_path = NULL; + } +} + /* This must be called once at every round of logfile checking. */ static @@ -1728,6 +1720,7 @@ int make_log_init(void *buf, struct mars_dent *dent) rot->copy_path = copy_path; rot->global = global; parent->d_private = rot; + parent->d_private_destruct = rot_destruct; } rot->replay_link = NULL; @@ -3453,7 +3446,7 @@ static const struct light_class light_classes[] = { #ifdef RUN_LOGINIT .cl_forward = make_log_init, #endif - .cl_backward = kill_log, + .cl_backward = kill_any, }, /* Dito for each individual size */ diff --git a/sy_old/strategy.h b/sy_old/strategy.h index f57f4896..433e7761 100644 --- a/sy_old/strategy.h +++ b/sy_old/strategy.h @@ -41,6 +41,7 @@ extern char *my_id(void); char *new_link; \ char *old_link; \ struct mars_global *d_global; \ + void (*d_private_destruct)(void *private); \ void *d_private; struct mars_dent { diff --git a/sy_old/sy_generic.c b/sy_old/sy_generic.c index 6206b68a..15ac1443 100644 --- a/sy_old/sy_generic.c +++ b/sy_old/sy_generic.c @@ -849,6 +849,9 @@ void mars_free_dent(struct mars_dent *dent) brick_string_free(dent->d_path); brick_string_free(dent->old_link); brick_string_free(dent->new_link); + if (dent->d_private_destruct) { + dent->d_private_destruct(dent->d_private); + } brick_mem_free(dent->d_private); brick_mem_free(dent); }