From 4247fafd0f361d2373df7213a1a0028554e93d93 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 13 Feb 2010 01:35:55 -0800 Subject: ext: fix memory leak when reentrant/multithreaded The optional C extension leaked memory due to improper use of the Ruby API, causing duplicated objects to never be garbage collected. I misread the Data_Make_Struct/Data_Wrap_Struct documentation and ended up passing NULL as the "free" argument instead of -1, causing the memory to never be freed. From README.EXT in the MRI source which I misread: > The free argument is the function to free the pointer > allocation. If this is -1, the pointer will be just freed. > The functions mark and free will be called from garbage > collector. --- ext/clogger_ext/clogger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ext') diff --git a/ext/clogger_ext/clogger.c b/ext/clogger_ext/clogger.c index da6b5d2..6e14938 100644 --- a/ext/clogger_ext/clogger.c +++ b/ext/clogger_ext/clogger.c @@ -188,7 +188,7 @@ static VALUE clogger_alloc(VALUE klass) { struct clogger *c; - return Data_Make_Struct(klass, struct clogger, clogger_mark, 0, c); + return Data_Make_Struct(klass, struct clogger, clogger_mark, -1, c); } static struct clogger *clogger_get(VALUE self) -- cgit v1.2.3-24-ge0c7