diff options
author | Pavan Deolasee | 2016-07-06 10:21:44 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-18 10:05:31 +0000 |
commit | 2504c99cb17d1a4b65fe0a22b96245d7a399d092 (patch) | |
tree | f0daea63cc9fdef455474f027cd674ada9e6d1c2 | |
parent | 11a9a1ddffaad01cd67f22e65843e2cd86c4540c (diff) |
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
-rw-r--r-- | src/backend/pgxc/copy/copyops.c | 5 | ||||
-rw-r--r-- | src/backend/pgxc/locator/redistrib.c | 7 | ||||
-rw-r--r-- | src/include/pgxc/copyops.h | 3 |
3 files changed, 10 insertions, 5 deletions
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 |