change API cs_close() to take pointer to handle as argument. this lets us invalidate the closed handle
diff --git a/cs.c b/cs.c
index d4afd4f..a96b435 100644
--- a/cs.c
+++ b/cs.c
@@ -177,12 +177,13 @@
 	}
 }
 
-cs_err cs_close(csh handle)
+cs_err cs_close(csh *handle)
 {
-	if (!handle)
+	if (*handle)
+		// invalid handle
 		return CS_ERR_CSH;
 
-	struct cs_struct *ud = (struct cs_struct *)(uintptr_t)handle;
+	struct cs_struct *ud = (struct cs_struct *)(*handle);
 
 	switch (ud->arch) {
 		case CS_ARCH_X86:
@@ -203,6 +204,9 @@
 	memset(ud, 0, sizeof(*ud));
 	cs_mem_free(ud);
 
+	// invalid this handle
+	*handle = 0;
+
 	return CS_ERR_OK;
 }
 
diff --git a/include/capstone.h b/include/capstone.h
index a233ce3..ce6abdb 100644
--- a/include/capstone.h
+++ b/include/capstone.h
@@ -232,12 +232,12 @@
  cached memory, thus access to any Capstone API after cs_close() might crash
  your application.
 
- @handle: handle returned by cs_open()
+ @handle: pointer to a handle returned by cs_open()
 
  @return CS_ERR_OK on success, or other value on failure (refer to cs_err enum
  for detailed error).
 */
-cs_err cs_close(csh handle);
+cs_err cs_close(csh *handle);
 
 /*
  Set option for disassembling engine at runtime
diff --git a/tests/test.c b/tests/test.c
index 1bdf6b2..9f32e08 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -189,7 +189,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_arm.c b/tests/test_arm.c
index 60e7dad..6bb8969 100644
--- a/tests/test_arm.c
+++ b/tests/test_arm.c
@@ -226,7 +226,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_arm64.c b/tests/test_arm64.c
index 1f8e435..8b44e17 100644
--- a/tests/test_arm64.c
+++ b/tests/test_arm64.c
@@ -184,7 +184,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_detail.c b/tests/test_detail.c
index 786a8bc..a320ba1 100644
--- a/tests/test_detail.c
+++ b/tests/test_detail.c
@@ -218,7 +218,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_mips.c b/tests/test_mips.c
index e4eb0c3..fb6ea96 100644
--- a/tests/test_mips.c
+++ b/tests/test_mips.c
@@ -131,7 +131,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_ppc.c b/tests/test_ppc.c
index 393eea2..548e0c5 100644
--- a/tests/test_ppc.c
+++ b/tests/test_ppc.c
@@ -123,7 +123,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }
 
diff --git a/tests/test_x86.c b/tests/test_x86.c
index 3ab2583..6086c58 100644
--- a/tests/test_x86.c
+++ b/tests/test_x86.c
@@ -201,7 +201,7 @@
 
 		printf("\n");
 
-		cs_close(handle);
+		cs_close(&handle);
 	}
 }