Fix pfree problem.
authorVadim B. Mikheev <vadim4o@yahoo.com>
Mon, 15 Sep 1997 14:29:01 +0000 (14:29 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Mon, 15 Sep 1997 14:29:01 +0000 (14:29 +0000)
src/backend/executor/nodeSort.c
src/backend/utils/sort/psort.c
src/include/utils/psort.h

index 9a61300efd15edab5a18210b29715439b26e3208..3dd8f4d70fbc056c603fd35a5633e2d979c546f0 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.9 1997/09/08 21:43:19 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.10 1997/09/15 14:27:37 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -112,6 +112,7 @@ ExecSort(Sort *node)
        ScanKey         sortkeys;
        HeapTuple       heapTuple;
        TupleTableSlot *slot;
+       bool should_free;
 
        /* ----------------
         *      get state info from node
@@ -171,12 +172,7 @@ ExecSort(Sort *node)
                 * ----------------
                 */
                slot = (TupleTableSlot *) sortstate->csstate.cstate.cs_ResultTupleSlot;
-               /* *** get_cs_ResultTupleSlot((CommonState) sortstate); */
-
                slot->ttc_tupleDescriptor = ExecGetTupType(outerNode);
-#if 0
-               slot->ttc_execTupDescriptor = ExecGetExecTupDesc(outerNode);
-#endif
                /* ----------------
                 *      finally set the sorted flag to true
                 * ----------------
@@ -198,26 +194,9 @@ ExecSort(Sort *node)
         *      at this point we grab a tuple from psort
         * ----------------
         */
-       heapTuple = psort_grabtuple(node);
-
-       if (heapTuple == NULL)
-       {
-/*             psort_end(node); */
-               return (ExecClearTuple(slot));
-       }
+       heapTuple = psort_grabtuple(node, &should_free);
 
-       ExecStoreTuple(heapTuple,       /* tuple to store */
-                                  slot,                /* slot to store in */
-                                  InvalidBuffer,               /* no buffer */
-                                  true);               /* free the palloc'd tuple */
-/*       printf("ExecSort: (%x)",node);print_slot(slot);printf("\n");*/
-       return slot;
-#if 0
-       return ExecStoreTuple(heapTuple,        /* tuple to store */
-                                                 slot, /* slot to store in */
-                                                 InvalidBuffer,                /* no buffer */
-                                                 true);/* free the palloc'd tuple */
-#endif
+       return (ExecStoreTuple(heapTuple, slot, InvalidBuffer, should_free));
 }
 
 /* ----------------------------------------------------------------
index b7e66235aad9b2b957ef78c7e26b8bb264bdb42e..c5fab144f01b95460d22ed777a38a50a6a9aeb9d 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.21 1997/09/08 21:49:33 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/sort/Attic/psort.c,v 1.22 1997/09/15 14:28:42 vadim Exp $
  *
  * NOTES
  *             Sorts the first relation into the second relation.
@@ -128,8 +128,6 @@ psort_begin(Sort *node, int nkeys, ScanKey key)
        bool            empty;                  /* to answer: is child node empty? */
 
        node->psortstate = (struct Psortstate *) palloc(sizeof(struct Psortstate));
-       if (node->psortstate == NULL)
-               return false;
 
        AssertArg(nkeys >= 1);
        AssertArg(key[0].sk_attno != 0);
@@ -648,7 +646,7 @@ dumptuples(FILE *file, Sort *node)
  *                                               a NULL indicating the last tuple has been processed.
  */
 HeapTuple
-psort_grabtuple(Sort *node)
+psort_grabtuple(Sort *node, bool *should_free)
 {
        register HeapTuple tup;
        long            tuplen;
@@ -668,7 +666,7 @@ psort_grabtuple(Sort *node)
 
                                /* Update current merged sort file position */
                                PS(node)->psort_current += tuplen;
-
+                               *should_free = true;
                                return tup;
                        }
                        else
@@ -680,7 +678,10 @@ psort_grabtuple(Sort *node)
        else
        {
                if (PS(node)->psort_current < PS(node)->tupcount)
-                       return PS(node)->memtuples[PS(node)->psort_current++];
+               {
+                       *should_free = false;
+                       return (PS(node)->memtuples[PS(node)->psort_current++]);
+               }
                else
                        return NULL;
        }
@@ -725,8 +726,6 @@ psort_end(Sort *node)
        if (!node->cleaned)
        {
                Assert(node != (Sort *) NULL);
-/*             Assert(PS(node) != (Psortstate *) NULL); */
-
                /*
                 * I'm changing this because if we are sorting a relation with no
                 * tuples, psortstate is NULL.
index 21366b2220f1fa0394f09f23cc49a97adc69bec9..5e1c97052da82d5f70672d41f7fba0ccaf28d2a6 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: psort.h,v 1.10 1997/09/08 21:55:14 momjian Exp $
+ * $Id: psort.h,v 1.11 1997/09/15 14:29:01 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -99,7 +99,7 @@ if (1) CODE; else
 
 /* psort.c */
 extern bool psort_begin(Sort *node, int nkeys, ScanKey key);
-extern HeapTuple psort_grabtuple(Sort *node);
+extern HeapTuple psort_grabtuple(Sort *node, bool *should_free);
 extern void psort_markpos(Sort *node);
 extern void psort_restorepos(Sort *node);
 extern void psort_end(Sort *node);