  	}
  
 diff --git a/src/libjasper/base/jas_stream.c b/src/libjasper/base/jas_stream.c
-index 9a88556..453adcf 100644
+index 9a88556..62d2d96 100644
 --- a/src/libjasper/base/jas_stream.c
 +++ b/src/libjasper/base/jas_stream.c
 @@ -212,7 +212,7 @@ jas_stream_t *jas_stream_memopen(char *buf, int bufsize)

-	since the file is open. */
 	if (unlink(obj->pathname)) {
-		/* We will try unlinking the file again after it is closed. */
-		obj->flags |= JAS_STREAM_FILEOBJ_DELONCLOSE;
+		jas_stream_destroy(stream);
+		return 0;
 	}
 
 	/* Use full buffering. */
@@ -553,7 +562,7 @@ int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...)
 	int ret;
 
 	va_start(ap, fmt);

 	jas_stream_puts(stream, buf);
 	va_end(ap);
 	return ret;
@@ -992,7 +1009,7 @@ static int mem_resize(jas_stream_memobj_t *m, int bufsize)
 	unsigned char *buf;
 
 	assert(m->buf_);
