mirror of https://github.com/schoebel/mars
light: fix memory leak in rot destruction
This commit is contained in:
parent
932a4c56ef
commit
a1ec9ec5db
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue