Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ext/pg_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,16 @@ static VALUE
pgconn_reset_start2( VALUE self, VALUE conninfo )
{
t_pg_connection *this = pg_get_connection( self );
/* Ensure conninfo is a valid C string before closing the connection. */
char *p_conninfo = StringValueCStr(conninfo);

/* Close old connection */
pgconn_close_socket_io( self );
PQfinish( this->pgconn );
this->pgconn = NULL; /* Ensure no double free can happen. */

/* Start new connection */
this->pgconn = gvl_PQconnectStart( StringValueCStr(conninfo) );
this->pgconn = gvl_PQconnectStart( p_conninfo );

if( this->pgconn == NULL )
rb_raise(rb_ePGerror, "PQconnectStart() unable to allocate PGconn structure");
Expand Down
5 changes: 5 additions & 0 deletions spec/pg/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,11 @@
end.to raise_error(PG::Error)
end

it "reset with invalid conninfo doesn't close the connection" do
expect{ @conn.send(:reset_start2, "\0") }.to raise_error(ArgumentError)
expect( @conn.exec("SELECT 1").values ).to eq([["1"]])
end


it "closes the IO fetched from #socket_io when the connection is closed", :without_transaction do
conn = PG.connect( @conninfo )
Expand Down
Loading