From 507a0a2ab09144f524e3239b7fc201ad1ad1b78e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 13 May 1999 07:29:22 +0000 Subject: Rip out QueryTreeList structure, root and branch. Querytree lists are now plain old garden-variety Lists, allocated with palloc, rather than specialized expansible-array data allocated with malloc. This substantially simplifies their handling and eliminates several sources of memory leakage. Several basic types of erroneous queries (syntax error, attempt to insert a duplicate key into a unique index) now demonstrably leak zero bytes per query. --- src/backend/parser/analyze.c | 47 +++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 31 deletions(-) (limited to 'src/backend/parser/analyze.c') diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 2384c70c9f..98c5748868 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: analyze.c,v 1.102 1999/05/12 07:17:18 thomas Exp $ + * $Id: analyze.c,v 1.103 1999/05/13 07:28:34 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -59,17 +59,12 @@ List *extras_after = NIL; * all transformed to Query while the rest stays the same. * */ -QueryTreeList * +List * parse_analyze(List *pl, ParseState *parentParseState) { - QueryTreeList *result; + List *result = NIL; ParseState *pstate; Query *parsetree; - int i = 0; - - result = malloc(sizeof(QueryTreeList)); - result->len = length(pl); - result->qtrees = (Query **) malloc(result->len * sizeof(Query *)); while (pl != NIL) { @@ -78,35 +73,25 @@ parse_analyze(List *pl, ParseState *parentParseState) if (pstate->p_target_relation != NULL) heap_close(pstate->p_target_relation); - if (extras_before != NIL) + while (extras_before != NIL) { - result->len += length(extras_before); - result->qtrees = (Query **) realloc(result->qtrees, result->len * sizeof(Query *)); - while (extras_before != NIL) - { - result->qtrees[i++] = transformStmt(pstate, lfirst(extras_before)); - if (pstate->p_target_relation != NULL) - heap_close(pstate->p_target_relation); - extras_before = lnext(extras_before); - } + result = lappend(result, + transformStmt(pstate, lfirst(extras_before))); + if (pstate->p_target_relation != NULL) + heap_close(pstate->p_target_relation); + extras_before = lnext(extras_before); } - extras_before = NIL; - result->qtrees[i++] = parsetree; + result = lappend(result, parsetree); - if (extras_after != NIL) + while (extras_after != NIL) { - result->len += length(extras_after); - result->qtrees = (Query **) realloc(result->qtrees, result->len * sizeof(Query *)); - while (extras_after != NIL) - { - result->qtrees[i++] = transformStmt(pstate, lfirst(extras_after)); - if (pstate->p_target_relation != NULL) - heap_close(pstate->p_target_relation); - extras_after = lnext(extras_after); - } + result = lappend(result, + transformStmt(pstate, lfirst(extras_after))); + if (pstate->p_target_relation != NULL) + heap_close(pstate->p_target_relation); + extras_after = lnext(extras_after); } - extras_after = NIL; pl = lnext(pl); pfree(pstate); -- cgit v1.2.1