This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new fe478af  flush weakrefs on update
fe478af is described below

commit fe478af6bc7a8e12b94662e4fa937a896fa9c652
Author: Sam Ruby <[email protected]>
AuthorDate: Wed Dec 13 16:57:51 2017 -0500

    flush weakrefs on update
---
 lib/whimsy/asf/ldap.rb | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/whimsy/asf/ldap.rb b/lib/whimsy/asf/ldap.rb
index 5e04e62..b3a5fe2 100644
--- a/lib/whimsy/asf/ldap.rb
+++ b/lib/whimsy/asf/ldap.rb
@@ -38,9 +38,11 @@ require 'net/http'
 require 'base64'
 require 'thread'
 require 'securerandom'
+require 'set'
 
 module ASF
   module LDAP
+     @@weakrefs = Set.new
 
      # Derived from the following sources:
      # * https://www.pingmybox.com/dashboard?location=304
@@ -139,11 +141,14 @@ module ASF
       ASF.ldap.unbind if ASF.ldap.bound? rescue nil
       ldap = ASF.init_ldap(true)
       if block
+        self.flush_weakrefs
         ldap.bind(dn, password, &block)
         ASF.init_ldap(true)
       else
         ldap.bind(dn, password)
       end
+    ensure
+      self.flush_weakrefs
     end
 
     # validate HTTP authorization, and optionally invoke a block bound to
@@ -358,6 +363,18 @@ module ASF
     elsif value and not value.instance_of? WeakRef
       object.instance_variable_set(attr, WeakRef.new(value))
     end
+
+    # keep track of which weak references are saved
+    @@weakrefs << attr if object == self
+  end
+
+  # remove weak references
+  def self.flush_weakrefs
+    @@weakrefs.each do |attr|
+      object.instance_variable_remove(attr)
+    end
+
+    @@weakrefs.clear
   end
 
   # shortcut for dereference weakref

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to