@@ -424,15 +424,20 @@ static PyObject *
424
424
PLy_function_build_args (FunctionCallInfo fcinfo , PLyProcedure * proc )
425
425
{
426
426
PyObject * volatile arg = NULL ;
427
- PyObject * volatile args = NULL ;
427
+ PyObject * args ;
428
428
int i ;
429
429
430
+ /*
431
+ * Make any Py*_New() calls before the PG_TRY block so that we can quickly
432
+ * return NULL on failure. We can't return within the PG_TRY block, else
433
+ * we'd miss unwinding the exception stack.
434
+ */
435
+ args = PyList_New (proc -> nargs );
436
+ if (!args )
437
+ return NULL ;
438
+
430
439
PG_TRY ();
431
440
{
432
- args = PyList_New (proc -> nargs );
433
- if (!args )
434
- return NULL ;
435
-
436
441
for (i = 0 ; i < proc -> nargs ; i ++ )
437
442
{
438
443
PLyDatumToOb * arginfo = & proc -> args [i ];
@@ -696,19 +701,34 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
696
701
* pltlevel ,
697
702
* pltrelid ,
698
703
* plttablename ,
699
- * plttableschema ;
700
- PyObject * pltargs ,
704
+ * plttableschema ,
705
+ * pltargs = NULL ,
701
706
* pytnew ,
702
- * pytold ;
703
- PyObject * volatile pltdata = NULL ;
707
+ * pytold ,
708
+ * pltdata ;
704
709
char * stroid ;
705
710
706
- PG_TRY ();
711
+ /*
712
+ * Make any Py*_New() calls before the PG_TRY block so that we can quickly
713
+ * return NULL on failure. We can't return within the PG_TRY block, else
714
+ * we'd miss unwinding the exception stack.
715
+ */
716
+ pltdata = PyDict_New ();
717
+ if (!pltdata )
718
+ return NULL ;
719
+
720
+ if (tdata -> tg_trigger -> tgnargs )
707
721
{
708
- pltdata = PyDict_New ();
709
- if (!pltdata )
722
+ pltargs = PyList_New (tdata -> tg_trigger -> tgnargs );
723
+ if (!pltargs )
724
+ {
725
+ Py_DECREF (pltdata );
710
726
return NULL ;
727
+ }
728
+ }
711
729
730
+ PG_TRY ();
731
+ {
712
732
pltname = PyString_FromString (tdata -> tg_trigger -> tgname );
713
733
PyDict_SetItemString (pltdata , "name" , pltname );
714
734
Py_DECREF (pltname );
@@ -848,12 +868,9 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
848
868
int i ;
849
869
PyObject * pltarg ;
850
870
851
- pltargs = PyList_New (tdata -> tg_trigger -> tgnargs );
852
- if (!pltargs )
853
- {
854
- Py_DECREF (pltdata );
855
- return NULL ;
856
- }
871
+ /* pltargs should have been allocated before the PG_TRY block. */
872
+ Assert (pltargs );
873
+
857
874
for (i = 0 ; i < tdata -> tg_trigger -> tgnargs ; i ++ )
858
875
{
859
876
pltarg = PyString_FromString (tdata -> tg_trigger -> tgargs [i ]);
@@ -874,6 +891,7 @@ PLy_trigger_build_args(FunctionCallInfo fcinfo, PLyProcedure *proc, HeapTuple *r
874
891
}
875
892
PG_CATCH ();
876
893
{
894
+ Py_XDECREF (pltargs );
877
895
Py_XDECREF (pltdata );
878
896
PG_RE_THROW ();
879
897
}
0 commit comments