Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dd9d78f

Browse files
committed
Fix volatile-safety issue in pltcl_SPI_execute_plan().
The "callargs" variable is modified within PG_TRY and then referenced within PG_CATCH, which is exactly the coding pattern we've now found to be unsafe. Marking "callargs" volatile would be problematic because it is passed by reference to some Tcl functions, so fix the problem by not modifying it within PG_TRY. We can just postpone the free() till we exit the PG_TRY construct, as is already done elsewhere in this same file. Also, fix failure to free(callargs) when exiting on too-many-arguments error. This is only a minor memory leak, but a leak nonetheless. In passing, remove some unnecessary "volatile" markings in the same function. Those doubtless are there because gcc 2.95.3 whinged about them, but we now know that its algorithm for complaining is many bricks shy of a load. This is certainly a live bug with compilers that optimize similarly to current gcc, so back-patch to all active branches.
1 parent df923be commit dd9d78f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/pl/tcl/pltcl.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,9 +2235,9 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
22352235
int j;
22362236
Tcl_HashEntry *hashent;
22372237
pltcl_query_desc *qdesc;
2238-
const char *volatile nulls = NULL;
2239-
CONST84 char *volatile arrayname = NULL;
2240-
CONST84 char *volatile loop_body = NULL;
2238+
const char *nulls = NULL;
2239+
CONST84 char *arrayname = NULL;
2240+
CONST84 char *loop_body = NULL;
22412241
int count = 0;
22422242
int callnargs;
22432243
CONST84 char **callargs = NULL;
@@ -2367,6 +2367,8 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
23672367
if (i != argc)
23682368
{
23692369
Tcl_SetResult(interp, usage, TCL_STATIC);
2370+
if (callargs)
2371+
ckfree((char *) callargs);
23702372
return TCL_ERROR;
23712373
}
23722374

@@ -2405,10 +2407,6 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
24052407
}
24062408
}
24072409

2408-
if (callargs)
2409-
ckfree((char *) callargs);
2410-
callargs = NULL;
2411-
24122410
/************************************************************
24132411
* Execute the plan
24142412
************************************************************/
@@ -2435,6 +2433,9 @@ pltcl_SPI_execute_plan(ClientData cdata, Tcl_Interp *interp,
24352433
}
24362434
PG_END_TRY();
24372435

2436+
if (callargs)
2437+
ckfree((char *) callargs);
2438+
24382439
return my_rc;
24392440
}
24402441

0 commit comments

Comments
 (0)