From 5051295aae3d85f6052568c8c86e4ef16c884b21 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Thu, 28 Jan 2016 15:07:43 +0000 Subject: [PATCH] bustle-pcap: stop leaking so much in parse_arguments() --- c-sources/bustle-pcap.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/c-sources/bustle-pcap.c b/c-sources/bustle-pcap.c index f68553a..29082c3 100644 --- a/c-sources/bustle-pcap.c +++ b/c-sources/bustle-pcap.c @@ -109,6 +109,7 @@ parse_arguments ( gchar *usage; GError *error = NULL; gboolean ret; + gint exit_status = -1; context = g_option_context_new ("FILENAME"); g_option_context_add_main_entries (context, entries, NULL); @@ -121,7 +122,9 @@ parse_arguments ( { fprintf (stderr, "%s\n", error->message); fprintf (stderr, "%s", usage); - exit (2); + + exit_status = 2; + goto out; } if (version) @@ -130,13 +133,17 @@ parse_arguments ( fprintf (stdout, "Copyright 2011 Will Thompson \n"); fprintf (stdout, "This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); fprintf (stdout, "Written by Will Thompson \n"); - exit (0); + + exit_status = 0; + goto out; } else if (session_specified && system_specified) { fprintf (stderr, "You may only specify one of --session and --system\n"); fprintf (stderr, "%s", usage); - exit (2); + + exit_status = 2; + goto out; } else if (system_specified) { @@ -153,10 +160,21 @@ parse_arguments ( { fprintf (stderr, "You must specify exactly one output filename\n"); fprintf (stderr, "%s", usage); - exit (2); + + exit_status = 2; + goto out; } - *filename = filenames[0]; + *filename = g_strdup (filenames[0]); + +out: + g_free (usage); + g_strfreev (filenames); + g_option_context_free (context); + g_clear_error (&error); + + if (exit_status > -1) + exit (exit_status); } static void @@ -196,6 +214,7 @@ main ( if (pcap == NULL) { fprintf (stderr, "%s", error->message); + g_clear_error (&error); exit (1); } @@ -214,6 +233,7 @@ main ( bustle_pcap_monitor_stop (pcap); g_object_unref (pcap); + g_free (filename); return 0; } -- 2.7.0.rc3