Fixed segmentation fault when trying to close posix stream. #225

This commit is contained in:
Nathan Moinvaziri 2018-01-30 12:19:36 -08:00
parent 34eff624c4
commit ceca477ed4

View File

@ -177,8 +177,12 @@ int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
int32_t mz_stream_posix_close(void *stream)
{
mz_stream_posix *posix = (mz_stream_posix*)stream;
int32_t closed = fclose(posix->handle);
posix->handle = NULL;
int32_t closed = 0;
if (posix->handle != NULL)
{
closed = fclose(posix->handle);
posix->handle = NULL;
}
if (closed != 0)
{
posix->error = errno;
@ -199,10 +203,13 @@ void *mz_stream_posix_create(void **stream)
posix = (mz_stream_posix *)malloc(sizeof(mz_stream_posix));
if (posix != NULL)
{
memset(posix, 0, sizeof(mz_stream_posix));
posix->stream.vtbl = &mz_stream_posix_vtbl;
}
if (stream != NULL)
*stream = posix;
return posix;
}