Author: cazfi
Date: Sun Dec 18 08:25:47 2016
New Revision: 34725

URL: http://svn.gna.org/viewcvs/freeciv?rev=34725&view=rev
Log:
Fixed crash when opening file for write fails while bzip2 or xz compression is 
in use.

See bug #25391

Modified:
    trunk/utility/ioz.c

Modified: trunk/utility/ioz.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/ioz.c?rev=34725&r1=34724&r2=34725&view=diff
==============================================================================
--- trunk/utility/ioz.c (original)
+++ trunk/utility/ioz.c Sun Dec 18 08:25:47 2016
@@ -215,6 +215,7 @@
   } else {
 #if defined(FREECIV_HAVE_LIBBZ2) || defined(FREECIV_HAVE_LIBLZMA)
     char test_mode[4];
+
     sz_strlcpy(test_mode, mode);
     sz_strlcat(test_mode, "b");
 #endif /* FREECIV_HAVE_LIBBZ2 || FREECIV_HAVE_LIBLZMA */
@@ -372,6 +373,10 @@
       fp->u.xz.out_index = 0;
       fp->u.xz.total_read = 0;
       fp->u.xz.plain = fc_fopen(filename, mode);
+      if (!fp->u.xz.plain) {
+        free(fp);
+        return NULL;
+      }
     }
     return fp;
 #endif /* FREECIV_HAVE_LIBLZMA */
@@ -388,9 +393,12 @@
       if (fp->u.bz2.error != BZ_OK) {
         int tmp_err; /* See comments for similar variable
                       * near BZ2_bzReadOpen() */
+
         BZ2_bzWriteClose(&tmp_err, fp->u.bz2.file, 0, NULL, NULL);
         fp->u.bz2.file = NULL;
       }
+    } else {
+      fp->u.bz2.file = NULL;
     }
     if (!fp->u.bz2.file) {
       if (fp->u.bz2.plain) {


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to