about summary refs log tree commit diff stats
path: root/miasm2/jitter/Jittcc.c
diff options
context:
space:
mode:
authorserpilliere <devnull@localhost>2014-08-25 15:55:34 +0200
committerserpilliere <devnull@localhost>2014-08-25 15:55:34 +0200
commitf12702ba8c804565123e3b97f7ff185e8bf8844a (patch)
treea1a0ad474be5a62a0b6e1cc8a8c5d770b54dc459 /miasm2/jitter/Jittcc.c
parent874d891deae98b48f5df36aa9fdfc4a29e9d2020 (diff)
downloadmiasm-f12702ba8c804565123e3b97f7ff185e8bf8844a.tar.gz
miasm-f12702ba8c804565123e3b97f7ff185e8bf8844a.zip
jittcc: free pointers
Diffstat (limited to 'miasm2/jitter/Jittcc.c')
-rw-r--r--miasm2/jitter/Jittcc.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c
index 2d309376..fb8b3e27 100644
--- a/miasm2/jitter/Jittcc.c
+++ b/miasm2/jitter/Jittcc.c
@@ -38,7 +38,7 @@ char **lib_array = NULL;
 //char *libcodenat_path = NULL;
 
 
-void tcc_init_state(void)
+TCCState * tcc_init_state(void)
 {
 	int i;
 
@@ -57,10 +57,20 @@ void tcc_init_state(void)
 	for (i=0;i<include_array_count; i++){
 		tcc_add_include_path(tcc_state, include_array[i]);
 	}
-}
 
+	return tcc_state;
+}
 
 
+PyObject* tcc_end(PyObject* self, PyObject* args)
+{
+	if (tcc_state) {
+		tcc_delete(tcc_state);
+		tcc_state = NULL;
+	}
+	Py_INCREF(Py_None);
+	return Py_None;
+}
 
 PyObject* tcc_set_emul_lib_path(PyObject* self, PyObject* args)
 {
@@ -109,6 +119,7 @@ PyObject* tcc_set_emul_lib_path(PyObject* self, PyObject* args)
 	*/
 	Py_INCREF(Py_None);
 
+	tcc_state = tcc_init_state();
 
 	return Py_None;
 }
@@ -133,8 +144,6 @@ PyObject* tcc_compil(PyObject* self, PyObject* args)
 	char* func_code;
 	int (*entry)(void);
 
-	tcc_init_state();
-
 	if (!PyArg_ParseTuple(args, "ss", &func_name, &func_code))
 		return NULL;
 
@@ -154,6 +163,7 @@ PyObject* tcc_compil(PyObject* self, PyObject* args)
 		fprintf(stderr, "%s\n", func_name);
 		exit(0);
 	}
+
 	return PyLong_FromUnsignedLongLong((uint64_t)entry);
 
 }
@@ -207,6 +217,8 @@ static PyMethodDef TccMethods[] = {
      "tcc exec bloc"},
     {"tcc_compil",  tcc_compil, METH_VARARGS,
      "tcc compil"},
+    {"tcc_end",  tcc_end, METH_VARARGS,
+     "tcc end"},
     {NULL, NULL, 0, NULL}        /* Sentinel */
 };