@@ -195,76 +195,6 @@ static void pg_decode_commit_txn(LogicalDecodingContext *ctx,
195
195
ReorderBufferTXN * txn , XLogRecPtr commit_lsn ) {
196
196
}
197
197
198
- /* convenience method to free up sub-messages */
199
- static void row_message_destroy (Decoderbufs__RowMessage * msg ) {
200
- if (!msg ) {
201
- return ;
202
- }
203
-
204
- if (msg -> table ) {
205
- pfree (msg -> table );
206
- }
207
-
208
- if (msg -> n_new_tuple > 0 ) {
209
- for (int i = 0 ; i < msg -> n_new_tuple ; i ++ ) {
210
- if (msg -> new_tuple [i ]) {
211
- switch (msg -> new_tuple [i ]-> datum_case ) {
212
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_STRING :
213
- if (msg -> new_tuple [i ]-> datum_string ) {
214
- pfree (msg -> new_tuple [i ]-> datum_string );
215
- }
216
- break ;
217
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_BYTES :
218
- if (msg -> new_tuple [i ]-> datum_bytes .data ) {
219
- pfree (msg -> new_tuple [i ]-> datum_bytes .data );
220
- msg -> new_tuple [i ]-> datum_bytes .data = NULL ;
221
- msg -> new_tuple [i ]-> datum_bytes .len = 0 ;
222
- }
223
- break ;
224
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_POINT :
225
- if (msg -> new_tuple [i ]-> datum_point ) {
226
- pfree (msg -> new_tuple [i ]-> datum_point );
227
- }
228
- break ;
229
- default :
230
- break ;
231
- }
232
- pfree (msg -> new_tuple [i ]);
233
- }
234
- }
235
- pfree (msg -> new_tuple );
236
- }
237
- if (msg -> n_old_tuple > 0 ) {
238
- for (int i = 0 ; i < msg -> n_old_tuple ; i ++ ) {
239
- if (msg -> old_tuple [i ]) {
240
- switch (msg -> old_tuple [i ]-> datum_case ) {
241
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_STRING :
242
- if (msg -> old_tuple [i ]-> datum_string ) {
243
- pfree (msg -> old_tuple [i ]-> datum_string );
244
- }
245
- break ;
246
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_BYTES :
247
- if (msg -> old_tuple [i ]-> datum_bytes .data ) {
248
- pfree (msg -> old_tuple [i ]-> datum_bytes .data );
249
- msg -> old_tuple [i ]-> datum_bytes .data = NULL ;
250
- msg -> old_tuple [i ]-> datum_bytes .len = 0 ;
251
- }
252
- break ;
253
- case DECODERBUFS__DATUM_MESSAGE__DATUM_DATUM_POINT :
254
- if (msg -> old_tuple [i ]-> datum_point ) {
255
- pfree (msg -> old_tuple [i ]-> datum_point );
256
- }
257
- break ;
258
- default :
259
- break ;
260
- }
261
- pfree (msg -> old_tuple [i ]);
262
- }
263
- }
264
- pfree (msg -> old_tuple );
265
- }
266
- }
267
-
268
198
/* print tuple datums (only used for debug-mode) */
269
199
static void print_tuple_datums (StringInfo out , Decoderbufs__DatumMessage * * tup ,
270
200
size_t n ) {
@@ -363,8 +293,6 @@ static double numeric_to_double_no_overflow(Numeric num) {
363
293
tmp )));
364
294
}
365
295
366
- pfree (tmp );
367
-
368
296
return val ;
369
297
}
370
298
@@ -676,17 +604,16 @@ static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
676
604
TupleDesc tupdesc ;
677
605
Decoderbufs__RowMessage rmsg = DECODERBUFS__ROW_MESSAGE__INIT ;
678
606
679
- elog (DEBUG1 , "Entering decode_change callback" );
607
+ elog (DEBUG1 , "Entering decode_change callback" );
608
+
609
+ /* Avoid leaking memory by using and resetting our own context */
610
+ data = ctx -> output_plugin_private ;
611
+ old = MemoryContextSwitchTo (data -> context );
680
612
681
613
replident = relation -> rd_rel -> relreplident ;
682
614
683
615
class_form = RelationGetForm (relation );
684
616
685
- data = ctx -> output_plugin_private ;
686
-
687
- /* Avoid leaking memory by using and resetting our own context */
688
- old = MemoryContextSwitchTo (data -> context );
689
-
690
617
RelationGetIndexList (relation );
691
618
is_rel_non_selective = (replident == REPLICA_IDENTITY_NOTHING ||
692
619
(replident == REPLICA_IDENTITY_DEFAULT &&
@@ -790,14 +717,10 @@ static void pg_decode_change(LogicalDecodingContext *ctx, ReorderBufferTXN *txn,
790
717
void * packed = palloc (psize );
791
718
size_t ssize = decoderbufs__row_message__pack (& rmsg , packed );
792
719
appendBinaryStringInfo (ctx -> out , packed , ssize );
793
- /* free packed buffer */
794
- pfree (packed );
795
720
}
796
721
OutputPluginWrite (ctx , true);
797
722
798
- /* cleanup msg */
799
- row_message_destroy (& rmsg );
800
-
723
+ /* Cleanup, freeing memory */
801
724
MemoryContextSwitchTo (old );
802
725
MemoryContextReset (data -> context );
803
726
}
0 commit comments