Skip to content

Commit 286f81a

Browse files
committed
fix: use global memory when the DBFLAG_PERSISTENT flag is set to avoid crash for double free
1 parent 2c310e5 commit 286f81a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/postgresql/database_postgresql.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,8 @@ int databasevm_prepare (cloudsync_context *data, const char *sql, dbvm_t **vm, i
986986
int rc = DBRES_OK;
987987
PG_TRY();
988988
{
989-
stmt->stmt_mcxt = AllocSetContextCreate(CurrentMemoryContext, "cloudsync stmt", ALLOCSET_DEFAULT_SIZES);
989+
MemoryContext parent = (flags & DBFLAG_PERSISTENT) ? TopMemoryContext : CurrentMemoryContext;
990+
stmt->stmt_mcxt = AllocSetContextCreate(parent, "cloudsync stmt", ALLOCSET_DEFAULT_SIZES);
990991
stmt->bind_mcxt = AllocSetContextCreate(stmt->stmt_mcxt, "cloudsync binds", ALLOCSET_DEFAULT_SIZES);
991992
stmt->row_mcxt = AllocSetContextCreate(stmt->stmt_mcxt, "cloudsync row", ALLOCSET_DEFAULT_SIZES);
992993

0 commit comments

Comments
 (0)