pgpool2.git / summary / log / commit / refs

commit    3daccc9c47cafb131b567471d6307af433e08cbc
Author:   Muhammad Usama <m.usama@gmail.com>
Date:     Wed Aug 06 14:59:16 2014 +0000

    Fix for the segmentation fault, which was unearthed while testing. The crash only
    exists in master branch, and was caused by import of memory manager.
    The reason for the crash was check_copy_from_stdin() function was making the persistent copies
    of copy_schema, copy_nulls and copy_table in wrong memory context, whose lifecycle
    is shorter than the lifecycle of global variables (copy_schema, copy_nulls and copy_table).
    This checkin fix the fault by replacing pstrdup() with
    MemoryContextStrdup() and using TopMemoryContext.


src/protocol/pool_process_query.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c index ecbc695fa..746afcaea 100644 --- a/src/protocol/pool_process_query.c +++ b/src/protocol/pool_process_query.c @@ -3418,13 +3418,14 @@ int check_copy_from_stdin(Node *node) /* query is COPY FROM STDIN */ if (relation->schemaname) - copy_schema = pstrdup(relation->schemaname); + copy_schema = MemoryContextStrdup(TopMemoryContext,relation->schemaname); else - copy_schema = pstrdup("public"); - copy_table = pstrdup(relation->relname); + copy_schema = MemoryContextStrdup(TopMemoryContext,"public"); + + copy_table = MemoryContextStrdup(TopMemoryContext,relation->relname); copy_delimiter = '\t'; /* default delimiter */ - copy_null = pstrdup("\\N"); /* default null string */ + copy_null = MemoryContextStrdup(TopMemoryContext,"\\N"); /* default null string */ /* look up delimiter and null string. */ foreach (lc, stmt->options) @@ -3440,9 +3441,9 @@ int check_copy_from_stdin(Node *node) else if (strcmp(elem->defname, "null") == 0) { if (copy_null) - free(copy_null); + pfree(copy_null); v = (Value *)elem->arg; - copy_null = pstrdup(v->val.str); + copy_null = MemoryContextStrdup(TopMemoryContext,v->val.str); } } } [parent: 4a2086417093]