feat(core/plan): 清理 effect 所持有的内存
This commit is contained in:
@@ -1,16 +1,39 @@
|
|||||||
#include "core/plan.h"
|
#include "core/plan.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "base/array.h"
|
#include "base/array.h"
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
|
|
||||||
|
static void free_memory_hold_by_effects(effect_t *effects, size_t count) {
|
||||||
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
auto effect = &effects[i];
|
||||||
|
|
||||||
|
switch (effect->type) {
|
||||||
|
case ZDWM_EFFECT_CHANGE_WINDOW_LIST:
|
||||||
|
p_delete(&effect->as.change_window_list.windows);
|
||||||
|
break;
|
||||||
|
case ZDWM_EFFECT_RESTACK_WINDOWS:
|
||||||
|
p_delete(&effect->as.restack_windows.windows);
|
||||||
|
break;
|
||||||
|
case ZDWM_EFFECT_BIND_KEY:
|
||||||
|
p_delete(&effect->as.bind_key.keys);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void plan_reset(plan_t *plan) {
|
void plan_reset(plan_t *plan) {
|
||||||
if (!plan->effects || !plan->capacity) return;
|
if (!plan->effects || !plan->capacity) return;
|
||||||
|
|
||||||
|
free_memory_hold_by_effects(plan->effects, plan->count);
|
||||||
p_clear(plan->effects, plan->capacity);
|
p_clear(plan->effects, plan->capacity);
|
||||||
plan->count = 0;
|
plan->count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plan_cleanup(plan_t *plan) {
|
void plan_cleanup(plan_t *plan) {
|
||||||
|
free_memory_hold_by_effects(plan->effects, plan->count);
|
||||||
p_delete(&plan->effects);
|
p_delete(&plan->effects);
|
||||||
plan->count = 0;
|
plan->count = 0;
|
||||||
plan->capacity = 0;
|
plan->capacity = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user