From: Pavan Deolasee Date: Wed, 6 Jul 2016 10:21:44 +0000 (+0530) Subject: Return pointer to the buffer used to store various fields values, so that X-Git-Tag: XL9_5_R1_2~33 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=4fea6d6a4d36865732c62d540d7e3318d7d87a74;p=postgres-xl.git Return pointer to the buffer used to store various fields values, so that caller can free up the memory when done with it. This fixes a memory like while running ALTER TABLE DISTRIBUTE BY --- diff --git a/src/backend/pgxc/copy/copyops.c b/src/backend/pgxc/copy/copyops.c index a85a06cc09..7e30a6cd6a 100644 --- a/src/backend/pgxc/copy/copyops.c +++ b/src/backend/pgxc/copy/copyops.c @@ -219,7 +219,8 @@ attribute_out_text(StringInfo buf, char *string) * redistribution and storage of tuple data into a tuple store. */ char ** -CopyOps_RawDataToArrayField(TupleDesc tupdesc, char *message, int len) +CopyOps_RawDataToArrayField(TupleDesc tupdesc, char *message, int len, + char **tmpbuf) { char delimc = COPYOPS_DELIMITER; int fieldno; @@ -243,7 +244,7 @@ CopyOps_RawDataToArrayField(TupleDesc tupdesc, char *message, int len) raw_fields = (char **) palloc(fields * sizeof(char *)); /* Take a copy of message to manipulate */ - origin_ptr = (char *) palloc0(sizeof(char) * (len + 1)); + *tmpbuf = origin_ptr = (char *) palloc0(sizeof(char) * (len + 1)); memcpy(origin_ptr, message, len + 1); /* Add clean separator '\0' at the end of message */ diff --git a/src/backend/pgxc/locator/redistrib.c b/src/backend/pgxc/locator/redistrib.c index 13074e885a..3fc36af8d0 100644 --- a/src/backend/pgxc/locator/redistrib.c +++ b/src/backend/pgxc/locator/redistrib.c @@ -535,11 +535,12 @@ distrib_copy_from(RedistribState *distribState, ExecNodes *exec_nodes) if (AttributeNumberIsValid(copyState->rel_loc->partAttrNum)) { char **fields; - + char *tmpbuf = NULL; + /* * Split message on an array of fields. */ - fields = CopyOps_RawDataToArrayField(tupdesc, data, len); + fields = CopyOps_RawDataToArrayField(tupdesc, data, len, &tmpbuf); Assert(partIdx >= 0); /* Determine partitioning value */ @@ -550,6 +551,8 @@ distrib_copy_from(RedistribState *distribState, ExecNodes *exec_nodes) is_null = false; } + if (tmpbuf) + pfree(tmpbuf); pfree(fields); } diff --git a/src/include/pgxc/copyops.h b/src/include/pgxc/copyops.h index 862dbbd299..4ddf159795 100644 --- a/src/include/pgxc/copyops.h +++ b/src/include/pgxc/copyops.h @@ -21,7 +21,8 @@ /* Type of data delimiter used for data redistribution using remote COPY */ #define COPYOPS_DELIMITER '\t' -extern char **CopyOps_RawDataToArrayField(TupleDesc tupdesc, char *message, int len); +extern char **CopyOps_RawDataToArrayField(TupleDesc tupdesc, char *message, + int len, char **tmpbuf); extern char *CopyOps_BuildOneRowTo(TupleDesc tupdesc, Datum *values, bool *nulls, int *len); #endif