Skip to content

Commit

Permalink
Merge pull request #482 from larskanis/no-double-free
Browse files Browse the repository at this point in the history
Move PQclear to the result stream loop, to let sequel_pg use it
  • Loading branch information
larskanis authored Oct 1, 2022
2 parents df27ef0 + 565edc9 commit b81b942
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions ext/pg_result.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ pgresult_type_map_get(VALUE self)
}


static void
static int
yield_hash(VALUE self, int ntuples, int nfields, void *data)
{
int tuple_num;
Expand All @@ -1393,10 +1393,10 @@ yield_hash(VALUE self, int ntuples, int nfields, void *data)
rb_yield(pgresult_aref(self, INT2NUM(tuple_num)));
}

pgresult_clear( this );
return 1; /* clear the result */
}

static void
static int
yield_array(VALUE self, int ntuples, int nfields, void *data)
{
int row;
Expand All @@ -1413,10 +1413,10 @@ yield_array(VALUE self, int ntuples, int nfields, void *data)
rb_yield( rb_ary_new4( nfields, row_values ));
}

pgresult_clear( this );
return 1; /* clear the result */
}

static void
static int
yield_tuple(VALUE self, int ntuples, int nfields, void *data)
{
int tuple_num;
Expand All @@ -1434,11 +1434,12 @@ yield_tuple(VALUE self, int ntuples, int nfields, void *data)
VALUE tuple = pgresult_tuple(copy, INT2FIX(tuple_num));
rb_yield( tuple );
}
return 0; /* don't clear the result */
}

/* Non-static, and data pointer for use by sequel_pg */
VALUE
pgresult_stream_any(VALUE self, void (*yielder)(VALUE, int, int, void*), void* data)
pgresult_stream_any(VALUE self, int (*yielder)(VALUE, int, int, void*), void* data)
{
t_pg_result *this;
int nfields;
Expand Down Expand Up @@ -1467,7 +1468,9 @@ pgresult_stream_any(VALUE self, void (*yielder)(VALUE, int, int, void*), void* d
pg_result_check( self );
}

yielder( self, ntuples, nfields, data );
if( yielder( self, ntuples, nfields, data ) ){
pgresult_clear( this );
}

if( gvl_PQisBusy(pgconn) ){
/* wait for input (without blocking) before reading each result */
Expand Down
2 changes: 1 addition & 1 deletion lib/pg/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PG
# Library version
VERSION = '1.4.3'
VERSION = '1.4.4'
end

0 comments on commit b81b942

Please sign in to comment.