diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-16 23:29:30 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-03-17 17:39:30 +0300 |
commit | cddc9bf83eb5cd2c69626b31ae7373342523b626 (patch) | |
tree | ec31133dd195914f2ffedf36717e436da2cf9c41 /src | |
parent | 06e48c350c2aed0f14d8f5b4957959055354dfd4 (diff) | |
download | sciteco-cddc9bf83eb5cd2c69626b31ae7373342523b626.tar.gz |
free some global objects even in the error case, in order to appease Valgrind
* If building with --enable-debug, we should always free all heap objects, even
if they would be freed on program termination anway, so they
won't appear as "possibly lost" in Valgrind.
I had this missing if munged or evaled macro failed, which resulted in lots
of false positives when running the testsuite under Valgrind.
* Also fixes possible crashes due to reusing already set GError variables.
This could theoretically happen if a munged script terminates with ^C
and its "quit" ED-hook would also throw any error.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -433,9 +433,8 @@ main(int argc, char **argv) teco_qreg_table_init_locals(&local_qregs, TRUE); if (!teco_ring_edit_by_name(NULL, &error)) { - g_fprintf(stderr, "Error editing unnamed file: %s\n", - error->message); - exit(EXIT_FAILURE); + g_prefix_error_literal(&error, "Error editing unnamed file: "); + goto cleanup; } /* @@ -458,10 +457,12 @@ main(int argc, char **argv) &local_qregs, &error) && !g_error_matches(error, TECO_ERROR, TECO_ERROR_QUIT)) { teco_error_add_frame_toplevel(); - goto error; + goto cleanup; } + g_clear_error(&error); + if (!teco_ed_hook(TECO_ED_HOOK_QUIT, &error)) - goto error; + goto cleanup; goto cleanup; } @@ -494,11 +495,12 @@ main(int argc, char **argv) */ if (!teco_execute_file(mung_filename, &local_qregs, &error) && !g_error_matches(error, TECO_ERROR, TECO_ERROR_QUIT)) - goto error; + goto cleanup; + g_clear_error(&error); if (teco_quit_requested) { if (!teco_ed_hook(TECO_ED_HOOK_QUIT, &error)) - goto error; + goto cleanup; goto cleanup; } } @@ -527,10 +529,10 @@ main(int argc, char **argv) if (!teco_cmdline_keypress(teco_fake_cmdline, strlen(teco_fake_cmdline), &error) && !g_error_matches(error, TECO_ERROR, TECO_ERROR_QUIT)) { teco_error_add_frame_toplevel(); - goto error; + goto cleanup; } } else if (!teco_interface_event_loop(&error)) { - goto error; + goto cleanup; } teco_machine_main_clear(&teco_cmdline.machine); @@ -548,7 +550,7 @@ main(int argc, char **argv) teco_view_set_scintilla_undo(teco_qreg_view, FALSE); if (!teco_ed_hook(TECO_ED_HOOK_QUIT, &error)) - goto error; + goto cleanup; cleanup: #ifndef NDEBUG @@ -559,9 +561,11 @@ cleanup: teco_view_free(teco_qreg_view); #endif teco_interface_cleanup(); - return 0; -error: - teco_error_display_full(error); - return EXIT_FAILURE; + if (error != NULL) { + teco_error_display_full(error); + return EXIT_FAILURE; + } + + return 0; } |