From b44f936f95f14af96fcec08e48df26ab24c481ed Mon Sep 17 00:00:00 2001 From: ser1zw Date: Sun, 5 Feb 2012 19:08:46 +0900 Subject: [PATCH] fix a memory leak of GUI::Trackbar --- ext/opencv/trackbar.cpp | 10 ++++++++-- ext/opencv/trackbar.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/opencv/trackbar.cpp b/ext/opencv/trackbar.cpp index 0e15958..183cd3c 100644 --- a/ext/opencv/trackbar.cpp +++ b/ext/opencv/trackbar.cpp @@ -30,7 +30,7 @@ void define_ruby_class() { return; /* * opencv = rb_define_module("OpenCV"); - * GUI = rb_define_module_under(opencv, "GUI"); + * GUI = rb_define_module_under(opencv, "GUI"); * * note: this comment is used by rdoc. */ @@ -46,13 +46,19 @@ void define_ruby_class() { VALUE rb_allocate(VALUE klass) { Trackbar *ptr; - return Data_Make_Struct(klass, Trackbar, trackbar_mark, 0, ptr); + return Data_Make_Struct(klass, Trackbar, trackbar_mark, trackbar_free, ptr); } void trackbar_mark(void *ptr) { rb_gc_mark(((Trackbar*)ptr)->block); } +void trackbar_free(void *ptr) { + Trackbar *trackbar = (Trackbar*)ptr; + free(trackbar->name); + free(trackbar); +} + /* * call-seq: * new(name,maxval[,val],&block) diff --git a/ext/opencv/trackbar.h b/ext/opencv/trackbar.h index 7205fea..ca08176 100644 --- a/ext/opencv/trackbar.h +++ b/ext/opencv/trackbar.h @@ -37,6 +37,7 @@ void define_ruby_class(); VALUE rb_allocate(VALUE klass); void trackbar_mark(void *ptr); +void trackbar_free(void *ptr); VALUE rb_initialize(int argc, VALUE *argv, VALUE self); VALUE rb_name(VALUE self);