Ensure connections are closed. Patch by Kristian Meier.

This commit is contained in:
emiel 2009-02-27 15:44:04 +00:00
parent afe6567a90
commit d6e6a97086
2 changed files with 56 additions and 34 deletions

View file

@ -1,4 +1,4 @@
=== Net::LDAP 0.0.5 / 2008-11-xx === Net::LDAP 0.0.5 / 2009-03-xx
* 13 minor enhancements: * 13 minor enhancements:
* Added Net::LDAP::Entry#to_ldif * Added Net::LDAP::Entry#to_ldif
@ -22,7 +22,7 @@
and marshalling. and marshalling.
* Migrated to 'hoe' as the new project droid. * Migrated to 'hoe' as the new project droid.
* 13 bugs fixed: * 14 bugs fixed:
* Silenced some annoying warnings in filter.rb. Thanks to "barjunk" * Silenced some annoying warnings in filter.rb. Thanks to "barjunk"
for pointing this out. for pointing this out.
* Some fairly extensive performance optimizations in the BER parser. * Some fairly extensive performance optimizations in the BER parser.
@ -43,7 +43,8 @@
* Allowed comma in filter strings, suggested by Kouhei. * Allowed comma in filter strings, suggested by Kouhei.
* 04Sep07, Changed four error classes to inherit from StandardError rather * 04Sep07, Changed four error classes to inherit from StandardError rather
Exception, in order to be friendlier to irb. Suggested by Kouhei. Exception, in order to be friendlier to irb. Suggested by Kouhei.
* Minor bug fixes here and there * Ensure connections are closed. Thanks to Kristian Meier.
* Minor bug fixes here and there.
=== Net::LDAP 0.0.4 / 2006-08-15 === Net::LDAP 0.0.4 / 2006-08-15

View file

@ -563,12 +563,15 @@ module Net
# if the bind was unsuccessful. # if the bind was unsuccessful.
def open def open
raise LdapError.new( "open already in progress" ) if @open_connection raise LdapError.new( "open already in progress" ) if @open_connection
begin
@open_connection = Connection.new( :host => @host, :port => @port, :encryption => @encryption ) @open_connection = Connection.new( :host => @host, :port => @port, :encryption => @encryption )
@open_connection.bind @auth @open_connection.bind @auth
yield self yield self
@open_connection.close ensure
@open_connection.close if @open_connection
@open_connection = nil @open_connection = nil
end end
end
# Searches the LDAP directory for directory entries. # Searches the LDAP directory for directory entries.
@ -664,6 +667,7 @@ module Net
} }
else else
@result = 0 @result = 0
begin
conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption ) conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption )
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.search( args ) {|entry| @result = conn.search( args ) {|entry|
@ -671,7 +675,9 @@ module Net
yield( entry ) if block_given? yield( entry ) if block_given?
} }
end end
conn.close ensure
conn.close if conn
end
end end
@result == 0 and result_set @result == 0 and result_set
@ -743,9 +749,12 @@ module Net
if @open_connection if @open_connection
@result = @open_connection.bind auth @result = @open_connection.bind auth
else else
begin
conn = Connection.new( :host => @host, :port => @port , :encryption => @encryption) conn = Connection.new( :host => @host, :port => @port , :encryption => @encryption)
@result = conn.bind auth @result = conn.bind auth
conn.close ensure
conn.close if conn
end
end end
@result == 0 @result == 0
@ -844,11 +853,14 @@ module Net
@result = @open_connection.add( args ) @result = @open_connection.add( args )
else else
@result = 0 @result = 0
begin
conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption) conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption)
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.add( args ) @result = conn.add( args )
end end
conn.close ensure
conn.close if conn
end
end end
@result == 0 @result == 0
end end
@ -939,11 +951,14 @@ module Net
@result = @open_connection.modify( args ) @result = @open_connection.modify( args )
else else
@result = 0 @result = 0
begin
conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption ) conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption )
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.modify( args ) @result = conn.modify( args )
end end
conn.close ensure
conn.close if conn
end
end end
@result == 0 @result == 0
end end
@ -1011,11 +1026,14 @@ module Net
@result = @open_connection.rename( args ) @result = @open_connection.rename( args )
else else
@result = 0 @result = 0
begin
conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption ) conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption )
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.rename( args ) @result = conn.rename( args )
end end
conn.close ensure
conn.close if conn
end
end end
@result == 0 @result == 0
end end
@ -1041,12 +1059,15 @@ module Net
@result = @open_connection.delete( args ) @result = @open_connection.delete( args )
else else
@result = 0 @result = 0
begin
conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption ) conn = Connection.new( :host => @host, :port => @port, :encryption => @encryption )
if (@result = conn.bind( args[:auth] || @auth )) == 0 if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.delete( args ) @result = conn.delete( args )
end end
ensure
conn.close conn.close
end end
end
@result == 0 @result == 0
end end