fix a double-free bug introduced by the last change in cs_disasm()
diff --git a/cs.c b/cs.c
index 911144a..a396b48 100644
--- a/cs.c
+++ b/cs.c
@@ -586,8 +586,11 @@
 		}
 	}
 
-	// no need to resize the cache if f == cache_size
-	if (f != cache_size) {
+	if (!c) {
+		cs_mem_free(total);
+		total = NULL;
+	} else if (f != cache_size) {
+		// no need to resize the cache if f == cache_size
 		// resize total to contain newly disasm insns
 		void *tmp = cs_mem_realloc(total, total_size - (cache_size - f) * sizeof(*insn_cache));
 		if (tmp == NULL) {	// insufficient memory
@@ -606,9 +609,6 @@
 		}
 
 		total = tmp;
-	} else if (!c) {
-		cs_mem_free(total);
-		total = NULL;
 	}
 
 	*insn = total;