bugfix to bring up correct error message if capture file couldn't be openened.
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 27 Feb 2005 18:52:05 +0000 (18:52 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 27 Feb 2005 18:52:05 +0000 (18:52 +0000)
some code cleanup

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@13537 f5534014-38df-0310-8fa8-9805f1628bb7

capture.c

index b8d6ad6b625a100d8f4fc8a82b854b9659cee90a..11bc47a45d3ace11a29d81e8cf4b7ec3b3ca6dd7 100644 (file)
--- a/capture.c
+++ b/capture.c
@@ -109,9 +109,9 @@ capture_open_output(capture_options *capture_opts, gboolean *is_tempfile) {
 
   /* did we fail to open the output file? */
   if (capture_opts->save_file_fd == -1) {
-    if (is_tempfile) {
+    if (*is_tempfile) {
       simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
-       "The temporary file to which the capture would be saved (\"%s\")"
+       "The temporary file to which the capture would be saved (\"%s\") "
        "could not be opened: %s.", capfile_name, strerror(errno));
     } else {
       if (capture_opts->multi_files_on) {
@@ -136,6 +136,18 @@ capture_open_output(capture_options *capture_opts, gboolean *is_tempfile) {
 }
 
 
+static void
+capture_close_output(capture_options *capture_opts)
+{
+    if (capture_opts->multi_files_on) {
+        ringbuf_free();
+    } else {
+        g_free(capture_opts->save_file);
+    }
+    capture_opts->save_file = NULL;
+}
+
+
 /* Open a specified file, or create a temporary file, and start a capture
    to the file in question.  */
 /* Returns TRUE if the capture starts successfully, FALSE otherwise. */
@@ -184,24 +196,14 @@ normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
     if (!capture_succeeded) {
       /* We didn't succeed in doing the capture, so we don't have a save
         file. */
-      if (capture_opts->multi_files_on) {
-       ringbuf_free();
-      } else {
-       g_free(capture_opts->save_file);
-      }
-      capture_opts->save_file = NULL;
+      capture_close_output(capture_opts);
       return FALSE;
     }
     /* Capture succeeded; attempt to read in the capture file. */
     if (cf_open(capture_opts->cf, capture_opts->save_file, is_tempfile, &err) != CF_OK) {
       /* We're not doing a capture any more, so we don't have a save
         file. */
-      if (capture_opts->multi_files_on) {
-       ringbuf_free();
-      } else {
-       g_free(capture_opts->save_file);
-      }
-      capture_opts->save_file = NULL;
+      capture_close_output(capture_opts);
       return FALSE;
     }
 
@@ -257,12 +259,7 @@ normal_do_capture(capture_options *capture_opts, gboolean is_tempfile)
 
     /* We're not doing a capture any more, so we don't have a save
        file. */
-    if (capture_opts->multi_files_on) {
-      ringbuf_free();
-    } else {
-      g_free(capture_opts->save_file);
-    }
-    capture_opts->save_file = NULL;
+    capture_close_output(capture_opts);
 
     /* if we didn't captured even a single packet, close the file again */
     if(cf_packet_count(capture_opts->cf) == 0) {