Skip to content

Commit bf4cbd9

Browse files
authored
Merge pull request #362 from renatocron/feat/fix-memory-leak
fix(postgres_text_reader.cpp): reset PGresult when result set is fully consumed to free resources immediately
2 parents 87d1075 + 22328e1 commit bf4cbd9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/postgres_text_reader.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,14 @@ PostgresReadResult PostgresTextReader::Read(DataChunk &output) {
365365
}
366366
}
367367
output.SetCardinality(scan_chunk.size());
368-
return row_offset < result->Count() ? PostgresReadResult::HAVE_MORE_TUPLES : PostgresReadResult::FINISHED;
368+
369+
bool finished = row_offset >= result->Count();
370+
if (finished) {
371+
// The result set is fully consumed. Reset immediately to free the PGresult.
372+
Reset();
373+
return PostgresReadResult::FINISHED;
374+
}
375+
return PostgresReadResult::HAVE_MORE_TUPLES;
369376
}
370377

371378
void PostgresTextReader::Reset() {

0 commit comments

Comments
 (0)