[PATCH] notmuch-dump.c: Fix output file being closed twice

classic Classic list List threaded Threaded
5 messages Options
Ralph Seichter-2 Ralph Seichter-2
Reply | Threaded
Open this post in threaded view
|

[PATCH] notmuch-dump.c: Fix output file being closed twice

Fixed: If the output file for a dump was non-writeable, gzclose_w()
was called twice on the output file handle, resulting in SIGABRT.
---
 notmuch-dump.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/notmuch-dump.c b/notmuch-dump.c
index 505c1469..78282661 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -329,11 +329,12 @@ notmuch_database_dump (notmuch_database_t *notmuch,
  }
     }
 
-    if (gzclose_w (output) != Z_OK) {
+    ret = gzclose_w (output);
+    output = NULL;
+    if (ret) {
  fprintf (stderr, "Error closing %s: %s\n", name_for_error,
  gzerror (output, NULL));
  ret = EXIT_FAILURE;
- output = NULL;
  goto DONE;
     }
 
--
2.21.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Ralph Seichter-2 Ralph Seichter-2
Reply | Threaded
Open this post in threaded view
|

[PATCH] notmuch-dump.c: Fix output file being closed twice (V2)

This is version 2 of the patch, sorry for that. I had sent an older
version by mistake.

-Ralph


_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Ralph Seichter-2 Ralph Seichter-2
Reply | Threaded
Open this post in threaded view
|

[PATCH] notmuch-dump.c: Fix output file being closed twice

Fixed: If the output file for a dump was non-writeable, gzclose_w()
was called twice on the output file handle, resulting in SIGABRT.
---
 notmuch-dump.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/notmuch-dump.c b/notmuch-dump.c
index 505c1469..ca73d003 100644
--- a/notmuch-dump.c
+++ b/notmuch-dump.c
@@ -329,13 +329,15 @@ notmuch_database_dump (notmuch_database_t *notmuch,
  }
     }
 
-    if (gzclose_w (output) != Z_OK) {
+    ret = gzclose_w (output);
+    if (ret) {
  fprintf (stderr, "Error closing %s: %s\n", name_for_error,
  gzerror (output, NULL));
  ret = EXIT_FAILURE;
- output = NULL;
+        output = NULL;
  goto DONE;
-    }
+    } else
+        output = NULL;
 
     if (output_file_name) {
  ret = rename (tempname, output_file_name);
--
2.21.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] notmuch-dump.c: Fix output file being closed twice

Ralph Seichter <[hidden email]> writes:

> Fixed: If the output file for a dump was non-writeable, gzclose_w()
> was called twice on the output file handle, resulting in SIGABRT.

LGTM, although I did have to revert one unrelated whitespace change.

I'll push that later if no-one objects.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] notmuch-dump.c: Fix output file being closed twice

David Bremner <[hidden email]> writes:

> Ralph Seichter <[hidden email]> writes:
>
>> Fixed: If the output file for a dump was non-writeable, gzclose_w()
>> was called twice on the output file handle, resulting in SIGABRT.
>
> LGTM, although I did have to revert one unrelated whitespace change.
>
> I'll push that later if no-one objects.

No one objected, pushed,

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch