diff --git a/bindings/go/unicorn/context.go b/bindings/go/unicorn/context.go index bf5ced9b..ed5bc636 100644 --- a/bindings/go/unicorn/context.go +++ b/bindings/go/unicorn/context.go @@ -17,7 +17,7 @@ func (u *uc) ContextSave(reuse Context) (Context, error) { if err := errReturn(C.uc_context_alloc(u.handle, ctx)); err != nil { return nil, err } - runtime.SetFinalizer(ctx, func(p Context) { C.uc_context_free(*p) }) + runtime.SetFinalizer(ctx, func(p Context) { C.uc_mem_free(*p) }) if err := errReturn(C.uc_context_save(u.handle, *ctx)); err != nil { } return ctx, nil diff --git a/bindings/haskell/src/Unicorn/Internal/Unicorn.chs b/bindings/haskell/src/Unicorn/Internal/Unicorn.chs index 30605282..fc2111c4 100644 --- a/bindings/haskell/src/Unicorn/Internal/Unicorn.chs +++ b/bindings/haskell/src/Unicorn/Internal/Unicorn.chs @@ -117,7 +117,7 @@ instance Storable MemoryRegion where -- | Opaque storage for CPU context, used with the context functions. {# pointer *uc_context as Context - foreign finalizer uc_context_free_wrapper as contextFree + foreign finalizer uc_mem_free_wrapper as memFree newtype #} @@ -125,11 +125,11 @@ instance Storable MemoryRegion where {# pointer *uc_context as ContextPtr -> Context #} -- | Make a CPU context out of a context pointer. The returned CPU context will --- automatically call 'uc_context_free' when it goes out of scope. +-- automatically call 'uc_mem_free' when it goes out of scope. mkContext :: ContextPtr -> IO Context mkContext ptr = - liftM Context (newForeignPtr contextFree ptr) + liftM Context (newForeignPtr memFree ptr) ------------------------------------------------------------------------------- -- Emulator control diff --git a/bindings/haskell/src/cbits/unicorn_wrapper.c b/bindings/haskell/src/cbits/unicorn_wrapper.c index fdbbe6d8..f92675c6 100644 --- a/bindings/haskell/src/cbits/unicorn_wrapper.c +++ b/bindings/haskell/src/cbits/unicorn_wrapper.c @@ -7,6 +7,6 @@ void uc_close_wrapper(uc_engine *uc) { void uc_close_dummy(uc_engine *uc) { } -void uc_context_free_wrapper(uc_context *context) { - uc_context_free(context); +void uc_mem_free_wrapper(void *mem) { + uc_mem_free(mem); } diff --git a/bindings/haskell/src/include/unicorn_wrapper.h b/bindings/haskell/src/include/unicorn_wrapper.h index e717c408..0fb17583 100644 --- a/bindings/haskell/src/include/unicorn_wrapper.h +++ b/bindings/haskell/src/include/unicorn_wrapper.h @@ -14,8 +14,8 @@ void uc_close_wrapper(uc_engine *uc); void uc_close_dummy(uc_engine *uc); /* - * Wrap Unicorn's uc_context_free function and ignore the returned error code. + * Wrap Unicorn's uc_mem_free function and ignore the returned error code. */ -void uc_context_free_wrapper(uc_context *context); +void uc_mem_free_wrapper(void *context); #endif diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c index bc9ca21a..40461cc7 100644 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -746,7 +746,7 @@ JNIEXPORT jlong JNICALL Java_unicorn_Unicorn_context_1alloc */ JNIEXPORT void JNICALL Java_unicorn_Unicorn_context_1free (JNIEnv *env, jobject self, jlong ctx) { - uc_err err = uc_context_free((uc_context*)ctx); + uc_err err = uc_mem_free((void *)ctx); if (err != UC_ERR_OK) { throwException(env, err); } diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index d62fb644..2c286720 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -126,7 +126,7 @@ _setup_prototype(_uc, "uc_mem_unmap", ucerr, uc_engine, ctypes.c_uint64, ctypes. _setup_prototype(_uc, "uc_mem_protect", ucerr, uc_engine, ctypes.c_uint64, ctypes.c_size_t, ctypes.c_uint32) _setup_prototype(_uc, "uc_query", ucerr, uc_engine, ctypes.c_uint32, ctypes.POINTER(ctypes.c_size_t)) _setup_prototype(_uc, "uc_context_alloc", ucerr, uc_engine, ctypes.POINTER(uc_context)) -_setup_prototype(_uc, "uc_context_free", ucerr, uc_context) +_setup_prototype(_uc, "uc_mem_free", ucerr, ctypes.c_void_p) _setup_prototype(_uc, "uc_context_save", ucerr, uc_engine, uc_context) _setup_prototype(_uc, "uc_context_restore", ucerr, uc_engine, uc_context) @@ -496,7 +496,7 @@ class SavedContext(object): self.pointer = pointer def __del__(self): - status = _uc.uc_context_free(self.pointer) + status = _uc.uc_mem_free(self.pointer) if status != uc.UC_ERR_OK: raise UcError(status) diff --git a/include/unicorn/unicorn.h b/include/unicorn/unicorn.h index 0aaab515..c34978b0 100644 --- a/include/unicorn/unicorn.h +++ b/include/unicorn/unicorn.h @@ -642,7 +642,7 @@ uc_err uc_mem_protect(uc_engine *uc, uint64_t address, size_t size, uint32_t per @uc: handle returned by uc_open() @regions: pointer to an array of uc_mem_region struct. This is allocated by - Unicorn, and must be freed by user later + Unicorn, and must be freed by user later with uc_mem_free() @count: pointer to number of struct uc_mem_region contained in @regions @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum @@ -660,6 +660,7 @@ uc_err uc_mem_regions(uc_engine *uc, uc_mem_region **regions, uint32_t *count); @uc: handle returned by uc_open() @context: pointer to a uc_engine*. This will be updated with the pointer to the new context on successful return of this function. + Later, this allocated memory must be freed with uc_mem_free(). @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum for detailed error). @@ -668,15 +669,16 @@ UNICORN_EXPORT uc_err uc_context_alloc(uc_engine *uc, uc_context **context); /* - Free the resource allocated by uc_context_alloc. + Free the memory allocated by uc_context_alloc & uc_mem_regions. - @context: handle returned by uc_context_alloc() + @mem: memory allocated by uc_context_alloc (returned in *context), or + by uc_mem_regions (returned in *regions) @return UC_ERR_OK on success, or other value on failure (refer to uc_err enum for detailed error). */ UNICORN_EXPORT -uc_err uc_context_free(uc_context *context); +uc_err uc_mem_free(void *mem); /* Save a copy of the internal CPU context. diff --git a/samples/sample_x86.c b/samples/sample_x86.c index 12af8372..46b8bfa2 100644 --- a/samples/sample_x86.c +++ b/samples/sample_x86.c @@ -759,9 +759,9 @@ static void test_i386_context_save(void) printf(">>> EAX = 0x%x\n", r_eax); // free the CPU context - err = uc_context_free(context); + err = uc_mem_free(context); if (err) { - printf("Failed on uc_context_free() with error returned: %u\n", err); + printf("Failed on uc_mem_free() with error returned: %u\n", err); return; } diff --git a/tests/regress/mem_64_c.c b/tests/regress/mem_64_c.c index b760fd08..d20a3fda 100644 --- a/tests/regress/mem_64_c.c +++ b/tests/regress/mem_64_c.c @@ -32,7 +32,7 @@ int main(int argc, char **argv, char **envp) { starts[i], regions[i].begin); } } - free(regions); + uc_mem_free(regions); } uc_close(uc); diff --git a/tests/unit/test_x86.c b/tests/unit/test_x86.c index 8218389c..6ffd7d24 100644 --- a/tests/unit/test_x86.c +++ b/tests/unit/test_x86.c @@ -800,7 +800,7 @@ static void test_i386_reg_save(void **state) assert_int_equal(eax, 2); // clean up; - uc_context_free(saved_context); + uc_mem_free(saved_context); uc_assert_success(uc_close(uc)); } /******************************************************************************/ diff --git a/uc.c b/uc.c index c68e7882..c162c3fc 100644 --- a/uc.c +++ b/uc.c @@ -28,10 +28,10 @@ static void free_table(gpointer key, gpointer value, gpointer data) { TypeInfo *ti = (TypeInfo*) value; - g_free((void*) ti->class); - g_free((void*) ti->name); - g_free((void*) ti->parent); - g_free((void*) ti); + g_free((void *) ti->class); + g_free((void *) ti->name); + g_free((void *) ti->parent); + g_free((void *) ti); } UNICORN_EXPORT @@ -1193,9 +1193,9 @@ uc_err uc_context_alloc(uc_engine *uc, uc_context **context) } UNICORN_EXPORT -uc_err uc_context_free(uc_context *context) +uc_err uc_mem_free(void *mem) { - free(context); + g_free(mem); return UC_ERR_OK; }