diff options
author | Dario Lombardo <lomato@gmail.com> | 2017-02-04 16:26:34 +0100 |
---|---|---|
committer | Dario Lombardo <lomato@gmail.com> | 2017-02-14 10:22:20 +0000 |
commit | 7c0c580c4b0093437ee81e11934ef5b8d27a5bb4 (patch) | |
tree | 45d46758e2ce26b82b8a5d066bd9b1f23e1165ec /reordercap.c | |
parent | ae0bdcc78c6cb2719e7aa5ae24e80584dec488a3 (diff) |
wiretap: add cleanup routine.
The cleanup routine has been added to exit section of the applications.
Those which required a exit restyle have been patched as well.
Change-Id: I3a8787f0718ac7fef00dc58176869c7510fda7b1
Reviewed-on: https://code.wireshark.org/review/19949
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Diffstat (limited to 'reordercap.c')
-rw-r--r-- | reordercap.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/reordercap.c b/reordercap.c index b56fcfdeed..006c33801e 100644 --- a/reordercap.c +++ b/reordercap.c @@ -51,6 +51,10 @@ #include <wsutil/report_err.h> +#define INVALID_OPTION 1 +#define OPEN_ERROR 2 +#define OUTPUT_FILE_ERROR 1 + /* Show command-line usage */ static void print_usage(FILE *output) @@ -182,6 +186,7 @@ main(int argc, char *argv[]) GArray *shb_hdrs = NULL; wtapng_iface_descriptions_t *idb_inf = NULL; GArray *nrb_hdrs = NULL; + int ret = EXIT_SUCCESS; GPtrArray *frames; FrameRecord_t *prevFrame = NULL; @@ -259,17 +264,18 @@ main(int argc, char *argv[]) "See https://www.wireshark.org for more information.\n", get_ws_vcs_version_info()); print_usage(stdout); - exit(0); + goto clean_exit; case 'v': comp_info_str = get_compiled_version_info(NULL, NULL); runtime_info_str = get_runtime_version_info(NULL); show_version("Reordercap (Wireshark)", comp_info_str, runtime_info_str); g_string_free(comp_info_str, TRUE); g_string_free(runtime_info_str, TRUE); - exit(0); + goto clean_exit; case '?': print_usage(stderr); - exit(1); + ret = INVALID_OPTION; + goto clean_exit; } } @@ -281,7 +287,8 @@ main(int argc, char *argv[]) } else { print_usage(stderr); - exit(1); + ret = INVALID_OPTION; + goto clean_exit; } /* Open infile */ @@ -295,7 +302,8 @@ main(int argc, char *argv[]) fprintf(stderr, "(%s)\n", err_info); g_free(err_info); } - exit(2); + ret = OPEN_ERROR; + goto clean_exit; } DEBUG_PRINT("file_type_subtype is %d\n", wtap_file_type_subtype(wth)); @@ -320,7 +328,8 @@ main(int argc, char *argv[]) outfile, wtap_strerror(err)); wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); - exit(1); + ret = OUTPUT_FILE_ERROR; + goto clean_exit; } /* Allocate the array of frame pointers. */ @@ -394,7 +403,8 @@ main(int argc, char *argv[]) wtap_strerror(err)); wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); - exit(1); + ret = OUTPUT_FILE_ERROR; + goto clean_exit; } wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); @@ -402,7 +412,9 @@ main(int argc, char *argv[]) /* Finally, close infile and release resources. */ wtap_close(wth); - return 0; +clean_exit: + wtap_cleanup(); + return ret; } /* |