summaryrefslogtreecommitdiff
path: root/ext/ffi_c
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2009-08-11 19:43:05 +1000
committerWayne Meissner <wmeissner@gmail.com>2009-08-11 19:43:05 +1000
commit05eec8d927ee04ce362e4a579b09e8d5f537ce43 (patch)
treee09c2bfbad672ef566dc915783a9fecd3ced41a2 /ext/ffi_c
parentbc1e80c2acd0603841618f99212318895539a100 (diff)
downloadffi-05eec8d927ee04ce362e4a579b09e8d5f537ce43.tar.gz
Use xmalloc/xfree for Buffer & MemoryPointer data storage allocations, so allocations will cause GC if there is no space available
Diffstat (limited to 'ext/ffi_c')
-rw-r--r--ext/ffi_c/Buffer.c4
-rw-r--r--ext/ffi_c/MemoryPointer.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/ext/ffi_c/Buffer.c b/ext/ffi_c/Buffer.c
index 99985a0..6538992 100644
--- a/ext/ffi_c/Buffer.c
+++ b/ext/ffi_c/Buffer.c
@@ -64,7 +64,7 @@ static void
buffer_release(Buffer* ptr)
{
if (ptr->storage != NULL) {
- free(ptr->storage);
+ xfree(ptr->storage);
ptr->storage = NULL;
}
@@ -84,7 +84,7 @@ buffer_initialize(int argc, VALUE* argv, VALUE self)
p->memory.typeSize = rbffi_type_size(rbSize);
p->memory.size = p->memory.typeSize * (nargs > 1 ? NUM2LONG(rbCount) : 1);
- p->storage = malloc(p->memory.size + 7);
+ p->storage = xmalloc(p->memory.size + 7);
if (p->storage == NULL) {
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%lu bytes", p->memory.size);
}
diff --git a/ext/ffi_c/MemoryPointer.c b/ext/ffi_c/MemoryPointer.c
index 9eaeb80..ea63d91 100644
--- a/ext/ffi_c/MemoryPointer.c
+++ b/ext/ffi_c/MemoryPointer.c
@@ -95,7 +95,7 @@ memptr_malloc(VALUE self, long size, long count, bool clear)
msize = size * count;
- p->storage = malloc(msize + 7);
+ p->storage = xmalloc(msize + 7);
if (p->storage == NULL) {
rb_raise(rb_eNoMemError, "Failed to allocate memory size=%ld bytes", msize);
}
@@ -158,7 +158,7 @@ static void
memptr_release(MemoryPointer* ptr)
{
if (ptr->autorelease && ptr->allocated && ptr->storage != NULL) {
- free(ptr->storage);
+ xfree(ptr->storage);
ptr->storage = NULL;
}
xfree(ptr);