From 87cad11d4f3010cfe0da486a1b83c790fe7ceb7a Mon Sep 17 00:00:00 2001 From: Kris Wehner Date: Wed, 9 Nov 2016 07:24:37 -0800 Subject: [PATCH] Move the output write outside the memory context, and fix the off by 1 error in the array iteration --- pgoutput/output_proto.c | 4 ++-- pgoutput/output_string.c | 1 - pgoutput/transicator_output.c | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pgoutput/output_proto.c b/pgoutput/output_proto.c index 20f9887..7a60562 100644 --- a/pgoutput/output_proto.c +++ b/pgoutput/output_proto.c @@ -70,6 +70,7 @@ static void tuple_to_proto( { int natt; int cp = 0; + int colnum = 0; for (natt = 0; natt < tupdesc->natts; natt++) { @@ -87,7 +88,7 @@ static void tuple_to_proto( col = (Common__ColumnPb*)palloc(sizeof(Common__ColumnPb)); common__column_pb__init(col); - cols[natt] = col; + cols[colnum++] = col; typ = attr->atttypid; col->name = NameStr(attr->attname); @@ -211,5 +212,4 @@ void transicatorOutputChangeProto( OutputPluginPrepareWrite(ctx, true); appendBinaryStringInfo(ctx->out, (char*)pack, packSize); - OutputPluginWrite(ctx, true); } diff --git a/pgoutput/output_string.c b/pgoutput/output_string.c index 52204ef..338da64 100644 --- a/pgoutput/output_string.c +++ b/pgoutput/output_string.c @@ -195,5 +195,4 @@ void transicatorOutputChangeString( } appendStringInfoChar(ctx->out, '}'); - OutputPluginWrite(ctx, true); } diff --git a/pgoutput/transicator_output.c b/pgoutput/transicator_output.c index 2f70de5..19d75f8 100644 --- a/pgoutput/transicator_output.c +++ b/pgoutput/transicator_output.c @@ -116,6 +116,7 @@ static void outputChange( /* Switch back to original context and release everything we "palloc"ed */ MemoryContextSwitchTo(oldMemCtx); MemoryContextReset(state->memCtx); + OutputPluginWrite(ctx, true); } void _PG_output_plugin_init(OutputPluginCallbacks *cb) {