Skip to content

Commit

Permalink
core: factor out freeing struct options members into a function
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Feb 20, 2024
1 parent ac376ad commit 4954c11
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
25 changes: 25 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,4 +915,29 @@ void options_postprocess_c2_lists(struct c2_state *state, struct x_connection *c
}
}

void options_destroy(struct options *options) {
// Free blacklists
c2_list_free(&options->shadow_blacklist, NULL);
c2_list_free(&options->shadow_clip_list, NULL);
c2_list_free(&options->fade_blacklist, NULL);
c2_list_free(&options->focus_blacklist, NULL);
c2_list_free(&options->invert_color_list, NULL);
c2_list_free(&options->blur_background_blacklist, NULL);
c2_list_free(&options->opacity_rules, NULL);
c2_list_free(&options->paint_blacklist, NULL);
c2_list_free(&options->unredir_if_possible_blacklist, NULL);
c2_list_free(&options->rounded_corners_blacklist, NULL);
c2_list_free(&options->corner_radius_rules, NULL);
c2_list_free(&options->window_shader_fg_rules, free);

free(options->write_pid_path);
free(options->logpath);

for (int i = 0; i < options->blur_kernel_count; ++i) {
free(options->blur_kerns[i]);
}
free(options->blur_kerns);
free(options->glx_fshader_win_str);
}

// vim: set noet sw=8 ts=8 :
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ bool must_use get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_e
win_option_mask_t *winopt_mask);
void options_postprocess_c2_lists(struct c2_state *state, struct x_connection *c,
struct options *option);
void options_destroy(struct options *options);

// vim: set noet sw=8 ts=8:
20 changes: 1 addition & 19 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2625,18 +2625,7 @@ static void session_destroy(session_t *ps) {
list_init_head(&ps->window_stack);

// Free blacklists
c2_list_free(&ps->o.shadow_blacklist, NULL);
c2_list_free(&ps->o.shadow_clip_list, NULL);
c2_list_free(&ps->o.fade_blacklist, NULL);
c2_list_free(&ps->o.focus_blacklist, NULL);
c2_list_free(&ps->o.invert_color_list, NULL);
c2_list_free(&ps->o.blur_background_blacklist, NULL);
c2_list_free(&ps->o.opacity_rules, NULL);
c2_list_free(&ps->o.paint_blacklist, NULL);
c2_list_free(&ps->o.unredir_if_possible_blacklist, NULL);
c2_list_free(&ps->o.rounded_corners_blacklist, NULL);
c2_list_free(&ps->o.corner_radius_rules, NULL);
c2_list_free(&ps->o.window_shader_fg_rules, free);
options_destroy(&ps->o);
c2_state_free(ps->c2_state);

// Free tgt_{buffer,picture} and root_picture
Expand All @@ -2655,13 +2644,6 @@ static void session_destroy(session_t *ps) {
pixman_region32_fini(&ps->screen_reg);
free(ps->expose_rects);

free(ps->o.write_pid_path);
free(ps->o.logpath);
for (int i = 0; i < ps->o.blur_kernel_count; ++i) {
free(ps->o.blur_kerns[i]);
}
free(ps->o.blur_kerns);
free(ps->o.glx_fshader_win_str);
x_free_monitor_info(&ps->monitors);

render_statistics_destroy(&ps->render_stats);
Expand Down

0 comments on commit 4954c11

Please sign in to comment.