Author: cazfi Date: Sun Dec 18 08:26:00 2016 New Revision: 34727 URL: http://svn.gna.org/viewcvs/freeciv?rev=34727&view=rev Log: Fixed crash when opening file for write fails while bzip2 or xz compression is in use.
See bug #25391 Modified: branches/S2_5/utility/ioz.c Modified: branches/S2_5/utility/ioz.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_5/utility/ioz.c?rev=34727&r1=34726&r2=34727&view=diff ============================================================================== --- branches/S2_5/utility/ioz.c (original) +++ branches/S2_5/utility/ioz.c Sun Dec 18 08:26:00 2016 @@ -192,6 +192,7 @@ } else { #if defined(HAVE_LIBBZ2) || defined(HAVE_LIBLZMA) char test_mode[4]; + sz_strlcpy(test_mode, mode); sz_strlcat(test_mode, "b"); #endif /* HAVE_LIBBZ2 || HAVE_LIBLZMA */ @@ -349,6 +350,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 /* HAVE_LIBLZMA */ @@ -365,9 +370,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