[Groonga-commit] groonga/groonga-command-parser at e4ac1ed [master] Ensure freeing raw yajl handle by GC

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 22 12:05:52 JST 2015


Kouhei Sutou	2015-05-22 12:05:52 +0900 (Fri, 22 May 2015)

  New Revision: e4ac1eda656b37b46b144d55fd7265c901e75357
  https://github.com/groonga/groonga-command-parser/commit/e4ac1eda656b37b46b144d55fd7265c901e75357

  Message:
    Ensure freeing raw yajl handle by GC

  Modified files:
    lib/groonga/command/parser/load-values-parser.rb

  Modified: lib/groonga/command/parser/load-values-parser.rb (+17 -1)
===================================================================
--- lib/groonga/command/parser/load-values-parser.rb    2015-05-21 23:25:58 +0900 (e74ec13)
+++ lib/groonga/command/parser/load-values-parser.rb    2015-05-22 12:05:52 +0900 (86d103e)
@@ -180,13 +180,29 @@ module Groonga
                                :yajl_allow_trailing_garbage,
                                :int,
                                1)
+          @finalizer = Finalizer.new(@handle)
+          ObjectSpace.define_finalizer(self, @finalizer)
         end
 
         def finalize_handle
           @callbacks_memory = nil
-          FFI_Yajl.yajl_free(@handle)
+          @finalizer.call(object_id)
+          ObjectSpace.undefine_finalizer(self)
+          @finalizer = nil
           @handle = nil
         end
+
+        class Finalizer
+          def initialize(handle)
+            @handle = handle
+          end
+
+          def call(object_id)
+            return if****@handl*****?
+            FFI_Yajl.yajl_free(@handle)
+            @handle = nil
+          end
+        end
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index