Skip to content

Fix some memory leaks

bob requested to merge bob131/crosswords:fix-memleaks into master

This commit fixes a number of instances of leaked memory, found via Valgrind's memcheck and visual inspection:

  • src/crosswords-misc.c (xwd_image_new_from_gresource): Drop ref on pixbuf once it's no longer needed. Found by audit; this function doesn't seem to ever be called, so this isn't a leak at the moment (strictly speaking). Fixes 875394e1.

  • src/picker-grid.c (picker_grid_load_hader), src/picker-list.c (set_label_face): Free font descriptions. Found by memcheck. Fixes e0867705 and 4dbe9396, respectively.

  • src/picker-list.c (picker_list_load_button): Clear downloader field before assigning a new instance to it. Found by audit (IIRC); not sure if this is triggerable in practice. Fixes 3bb9b8a7.

  • src/play-cell.c (measure_text_width): Free layout. Found by memcheck; in some situations, this leak causes the process memory usage to jump by megabytes at a time when changing cell focus! Fixes 972939d2.

  • src/play-clue-list.c (play_clue_list_init): Delete spurious extra ref on an already-owned reference. Found by memcheck. Fixes a799defc.

  • src/puzzle-downloader.c (on_file_response_dialog): Unrefs the dialog, since GtkNativeDialog instances aren't unreffed by gtk_native_dialog_destroy in the same way as other dialogs are by gtk_window_destroy. Found by memcheck. Fixes 92d97da7. (run_file_dialog): Unref filters once they've been added to the file chooser. Found by memcheck. Fixes dac6c632.

  • src/puzzle-picker.c (puzzle_picker_finalize): Free the puzzle picker ID during finalisation. Found by memcheck. Fixes f083e1e0. (build_basename_from_puzzle): Tag the built file name with g_autofree. Found by memcheck. Fixes 5151b0dc. (puzzle_picker_real_load_uri): Tag the created GFile instances with g_autoptr. Found with memcheck. Fixes 1b0b1ced.

  • src/puzzle-set-list.c (puzzle_set_list_init), src/puzzle-set.c (puzzle_sets_init): GStrv is meant for use with g_auto rather than g_autofree, so replace the latter with the former to prevent some leaks. Found by memcheck. Fixes 88a4d021 and d3ee2711, respectively.

  • src/puzzle-set-resource.c (puzzle_set_load_from_resource): Tag the GBytes read from a resource with g_autoptr. Found by memcheck. Fixes 6f5fd4bb.

Merge request reports