Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8c2f099

Browse files
committed
Fix memory overhelding while forming index' result:
memory allocation for ItemPointerData of heap' tuple is useless because of FormRetrieveIndexResult makes neccessary palloc.
1 parent 5d7e44f commit 8c2f099

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

src/backend/access/nbtree/nbtsearch.c

+4-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.9 1996/11/13 20:47:20 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.10 1996/11/21 06:10:55 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -535,7 +535,6 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
535535
RetrieveIndexResult res;
536536
BlockNumber blkno;
537537
ItemPointer current;
538-
ItemPointer iptr;
539538
BTItem btitem;
540539
IndexTuple itup;
541540
BTScanOpaque so;
@@ -569,10 +568,7 @@ _bt_next(IndexScanDesc scan, ScanDirection dir)
569568
itup = &btitem->bti_itup;
570569

571570
if (_bt_checkqual(scan, itup)) {
572-
iptr = (ItemPointer) palloc(sizeof(ItemPointerData));
573-
memmove((char *) iptr, (char *) &(itup->t_tid),
574-
sizeof(ItemPointerData));
575-
res = FormRetrieveIndexResult(current, iptr);
571+
res = FormRetrieveIndexResult(current, &(itup->t_tid));
576572

577573
/* remember which buffer we have pinned and locked */
578574
so->btso_curbuf = buf;
@@ -608,7 +604,6 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
608604
BTItem btitem;
609605
IndexTuple itup;
610606
ItemPointer current;
611-
ItemPointer iptr;
612607
BlockNumber blkno;
613608
StrategyNumber strat;
614609
RetrieveIndexResult res;
@@ -764,11 +759,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
764759
itup = &btitem->bti_itup;
765760

766761
if (_bt_checkqual(scan, itup)) {
767-
iptr = (ItemPointer) palloc(sizeof(ItemPointerData));
768-
memmove((char *) iptr, (char *) &(itup->t_tid),
769-
sizeof(ItemPointerData));
770-
res = FormRetrieveIndexResult(current, iptr);
771-
pfree(iptr);
762+
res = FormRetrieveIndexResult(current, &(itup->t_tid));
772763

773764
/* remember which buffer we have pinned */
774765
so->btso_curbuf = buf;
@@ -1035,7 +1026,6 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
10351026
Page page;
10361027
BTPageOpaque opaque;
10371028
ItemPointer current;
1038-
ItemPointer iptr;
10391029
OffsetNumber offnum, maxoff;
10401030
OffsetNumber start = 0;
10411031
BlockNumber blkno;
@@ -1132,10 +1122,7 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
11321122

11331123
/* see if we picked a winner */
11341124
if (_bt_checkqual(scan, itup)) {
1135-
iptr = (ItemPointer) palloc(sizeof(ItemPointerData));
1136-
memmove((char *) iptr, (char *) &(itup->t_tid),
1137-
sizeof(ItemPointerData));
1138-
res = FormRetrieveIndexResult(current, iptr);
1125+
res = FormRetrieveIndexResult(current, &(itup->t_tid));
11391126

11401127
/* remember which buffer we have pinned */
11411128
so = (BTScanOpaque) scan->opaque;

src/backend/access/rtree/rtget.c

+7-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.6 1996/11/05 10:54:16 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.7 1996/11/21 06:13:43 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -66,7 +66,6 @@ rtfirst(IndexScanDesc s, ScanDirection dir)
6666
RTSTACK *stk;
6767
BlockNumber blk;
6868
IndexTuple it;
69-
ItemPointer ip;
7069

7170
b = ReadBuffer(s->relation, P_ROOT);
7271
p = BufferGetPage(b);
@@ -106,13 +105,10 @@ rtfirst(IndexScanDesc s, ScanDirection dir)
106105
ItemPointerSet(&(s->currentItemData), BufferGetBlockNumber(b), n);
107106

108107
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
109-
ip = (ItemPointer) palloc(sizeof(ItemPointerData));
110-
memmove((char *) ip, (char *) &(it->t_tid),
111-
sizeof(ItemPointerData));
112-
ReleaseBuffer(b);
113108

114-
res = FormRetrieveIndexResult(&(s->currentItemData), ip);
109+
res = FormRetrieveIndexResult(&(s->currentItemData), &(it->t_tid));
115110

111+
ReleaseBuffer(b);
116112
return (res);
117113
} else {
118114
stk = (RTSTACK *) palloc(sizeof(RTSTACK));
@@ -145,7 +141,6 @@ rtnext(IndexScanDesc s, ScanDirection dir)
145141
RTSTACK *stk;
146142
BlockNumber blk;
147143
IndexTuple it;
148-
ItemPointer ip;
149144

150145
blk = ItemPointerGetBlockNumber(&(s->currentItemData));
151146
n = ItemPointerGetOffsetNumber(&(s->currentItemData));
@@ -191,13 +186,10 @@ rtnext(IndexScanDesc s, ScanDirection dir)
191186
ItemPointerSet(&(s->currentItemData), BufferGetBlockNumber(b), n);
192187

193188
it = (IndexTuple) PageGetItem(p, PageGetItemId(p, n));
194-
ip = (ItemPointer) palloc(sizeof(ItemPointerData));
195-
memmove((char *) ip, (char *) &(it->t_tid),
196-
sizeof(ItemPointerData));
197-
ReleaseBuffer(b);
198189

199-
res = FormRetrieveIndexResult(&(s->currentItemData), ip);
190+
res = FormRetrieveIndexResult(&(s->currentItemData), &(it->t_tid));
200191

192+
ReleaseBuffer(b);
201193
return (res);
202194
} else {
203195
stk = (RTSTACK *) palloc(sizeof(RTSTACK));
@@ -288,6 +280,8 @@ rtscancache(IndexScanDesc s, ScanDirection dir)
288280
else
289281
res = (RetrieveIndexResult) NULL;
290282

283+
pfree (ip);
284+
291285
return (res);
292286
}
293287

0 commit comments

Comments
 (0)