@@ -73,13 +73,16 @@ spi_response_t *__error_spi_resp(MemoryContext ctx, int ret, char *error)
73
73
spi_response_t * r ;
74
74
75
75
r = MemoryContextAlloc (ctx , sizeof (spi_response_t ));
76
+ if (!r ) return NULL ;
77
+
76
78
r -> n_rows = 0 ;
77
79
r -> n_attrs = 0 ;
78
80
r -> retval = ret ;
79
81
r -> types = NULL ;
80
82
r -> rows = NULL ;
81
83
r -> ref = NULL ;
82
84
r -> error = _mcopy_string (ctx , error );
85
+ if (!(r -> error ) return NULL ;
83
86
84
87
return r ;
85
88
}
@@ -93,6 +96,7 @@ spi_response_t *__copy_spi_data(MemoryContext ctx, int ret, int n)
93
96
94
97
95
98
r = MemoryContextAlloc (ctx , sizeof (spi_response_t ));
99
+ if (!r ) return NULL ;
96
100
r -> retval = ret ;
97
101
r -> error = NULL ;
98
102
@@ -109,9 +113,11 @@ spi_response_t *__copy_spi_data(MemoryContext ctx, int ret, int n)
109
113
r -> n_rows = n ;
110
114
r -> n_attrs = SPI_tuptable -> tupdesc -> natts ;
111
115
r -> types = MemoryContextAlloc (ctx , sizeof (Oid ) * r -> n_attrs );
116
+ if (!r -> types ) return NULL ;
112
117
r -> rows = MemoryContextAlloc (ctx , sizeof (spi_val_t * ) * n );
118
+ if (!r -> rows ) return NULL ;
113
119
r -> ref = MemoryContextAlloc (ctx , sizeof (bool ) * r -> n_attrs );
114
-
120
+ if (! r -> ref ) return NULL ;
115
121
116
122
for (i = 0 ; i < r -> n_attrs ; i ++ )
117
123
{
@@ -122,6 +128,7 @@ spi_response_t *__copy_spi_data(MemoryContext ctx, int ret, int n)
122
128
for (i = 0 ; i < n ; i ++ )
123
129
{
124
130
r -> rows [i ] = MemoryContextAlloc (ctx , sizeof (spi_val_t ) * r -> n_attrs );
131
+ if (!(r -> rows [i ])) return NULL ;
125
132
for (j = 0 ; j < r -> n_attrs ; j ++ )
126
133
{
127
134
dat = SPI_getbinval (SPI_tuptable -> vals [i ],
@@ -152,6 +159,7 @@ char *_mcopy_string(MemoryContext ctx, char *str)
152
159
if (!ctx ) ctx = SchedulerWorkerContext ;
153
160
154
161
cpy = MemoryContextAlloc (ctx , sizeof (char ) * (len + 1 ));
162
+ if (!cpy ) return NULL ;
155
163
156
164
memcpy (cpy , str , len );
157
165
cpy [len ] = 0 ;
@@ -165,6 +173,7 @@ char *my_copy_string(char *str)
165
173
char * cpy ;
166
174
167
175
cpy = palloc (sizeof (char ) * (len + 1 ));
176
+ if (!cpy ) return NULL ;
168
177
169
178
memcpy (cpy , str , len );
170
179
cpy [len ] = 0 ;
@@ -497,6 +506,11 @@ spi_response_t *execute_spi_sql_with_args(MemoryContext ctx, const char *sql, in
497
506
ret = SPI_execute_with_args (sql , n , argtypes , values , nulls , false, 0 );
498
507
MemoryContextSwitchTo (ctx );
499
508
rv = __copy_spi_data (ctx , ret , SPI_processed );
509
+ if (!rv )
510
+ {
511
+ elog (LOG , "ESSWA: Cannot allocate memory while copy resp data" );
512
+ return NULL ;
513
+ }
500
514
ReleaseCurrentSubTransaction ();
501
515
MemoryContextSwitchTo (ctx );
502
516
CurrentResourceOwner = oldowner ;
@@ -518,6 +532,11 @@ spi_response_t *execute_spi_sql_with_args(MemoryContext ctx, const char *sql, in
518
532
{
519
533
rv = __error_spi_resp (ctx , ret , "unknown error" );
520
534
}
535
+ if (!rv )
536
+ {
537
+ elog (LOG , "ESSWA: Cannot allocate memory while reporting error" );
538
+ return NULL ;
539
+ }
521
540
RollbackAndReleaseCurrentSubTransaction ();
522
541
CurrentResourceOwner = oldowner ;
523
542
MemoryContextSwitchTo (ctx );
@@ -550,6 +569,11 @@ spi_response_t *execute_spi_sql_with_args(MemoryContext ctx, const char *sql, in
550
569
sprintf (other , "error number: %d" , ret );
551
570
rv = __error_spi_resp (ctx , ret , other );
552
571
}
572
+ if (!rv )
573
+ {
574
+ elog (LOG , "ESSWA: Cannot allocate memory while reporting pg error" );
575
+ return NULL ;
576
+ }
553
577
}
554
578
555
579
return rv ;
@@ -595,6 +619,11 @@ spi_response_t *execute_spi_params_prepared(MemoryContext ctx, const char *sql,
595
619
SetCurrentStatementStartTimestamp ();
596
620
ret = SPI_execute_plan (plan , values , NULL , false, 0 );
597
621
rv = __copy_spi_data (ctx , ret , SPI_processed );
622
+ if (!rv )
623
+ {
624
+ elog (LOG , "ESSWAP: Cannot allocate memory while copy data" );
625
+ return NULL ;
626
+ }
598
627
}
599
628
ReleaseCurrentSubTransaction ();
600
629
switch_to_worker_context ();
@@ -618,6 +647,11 @@ spi_response_t *execute_spi_params_prepared(MemoryContext ctx, const char *sql,
618
647
{
619
648
rv = __error_spi_resp (ctx , ret , "unknown error" );
620
649
}
650
+ if (!rv )
651
+ {
652
+ elog (LOG , "ESSWAP: Cannot allocate memory while report error" );
653
+ return NULL ;
654
+ }
621
655
FreeErrorData (edata );
622
656
FlushErrorState ();
623
657
RollbackAndReleaseCurrentSubTransaction ();
@@ -653,6 +687,11 @@ spi_response_t *execute_spi_params_prepared(MemoryContext ctx, const char *sql,
653
687
sprintf (other , "error number: %d" , ret );
654
688
rv = __error_spi_resp (ctx , ret , other );
655
689
}
690
+ if (!rv )
691
+ {
692
+ elog (LOG , "ESSWAP: Cannot allocate memory while report pg error" );
693
+ return NULL ;
694
+ }
656
695
}
657
696
658
697
return rv ;
0 commit comments