8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.59 2000/01/31 04:35:51 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/utils/cache/catcache.c,v 1.60 2000/02/04 03:16:03 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -905,7 +905,7 @@ SearchSysCache(struct catcache * cache,
905
905
CatCTup * nct ;
906
906
CatCTup * nct2 ;
907
907
Dlelem * elt ;
908
- HeapTuple ntp = 0 ;
908
+ HeapTuple ntp = NULL ;
909
909
910
910
Relation relation ;
911
911
MemoryContext oldcxt ;
@@ -1039,32 +1039,42 @@ SearchSysCache(struct catcache * cache,
1039
1039
* wieck - 10/18/1996
1040
1040
* ----------
1041
1041
*/
1042
+ HeapTuple indextp ;
1043
+
1042
1044
MemoryContextSwitchTo (oldcxt );
1043
1045
Assert (cache -> cc_iscanfunc );
1044
1046
switch (cache -> cc_nkeys )
1045
1047
{
1046
1048
case 4 :
1047
- ntp = cache -> cc_iscanfunc (relation , v1 , v2 , v3 , v4 );
1049
+ indextp = cache -> cc_iscanfunc (relation , v1 , v2 , v3 , v4 );
1048
1050
break ;
1049
1051
case 3 :
1050
- ntp = cache -> cc_iscanfunc (relation , v1 , v2 , v3 );
1052
+ indextp = cache -> cc_iscanfunc (relation , v1 , v2 , v3 );
1051
1053
break ;
1052
1054
case 2 :
1053
- ntp = cache -> cc_iscanfunc (relation , v1 , v2 );
1055
+ indextp = cache -> cc_iscanfunc (relation , v1 , v2 );
1054
1056
break ;
1055
1057
case 1 :
1056
- ntp = cache -> cc_iscanfunc (relation , v1 );
1058
+ indextp = cache -> cc_iscanfunc (relation , v1 );
1059
+ break ;
1060
+ default :
1061
+ indextp = NULL ;
1057
1062
break ;
1058
1063
}
1059
1064
/* ----------
1060
1065
* Back to Cache context. If we got a tuple copy it
1061
- * into our context.
1062
- * wieck - 10/18/1996
1066
+ * into our context. wieck - 10/18/1996
1067
+ * And free the tuple that was allocated in the
1068
+ * transaction's context. tgl - 02/03/2000
1063
1069
* ----------
1064
1070
*/
1071
+ if (HeapTupleIsValid (indextp )) {
1072
+ MemoryContextSwitchTo ((MemoryContext ) CacheCxt );
1073
+ ntp = heap_copytuple (indextp );
1074
+ MemoryContextSwitchTo (oldcxt );
1075
+ heap_freetuple (indextp );
1076
+ }
1065
1077
MemoryContextSwitchTo ((MemoryContext ) CacheCxt );
1066
- if (HeapTupleIsValid (ntp ))
1067
- ntp = heap_copytuple (ntp );
1068
1078
}
1069
1079
else
1070
1080
{
@@ -1089,6 +1099,7 @@ SearchSysCache(struct catcache * cache,
1089
1099
{
1090
1100
CACHE1_elog (DEBUG , "SearchSysCache: found tuple" );
1091
1101
ntp = heap_copytuple (ntp );
1102
+ /* We should not free the result of heap_getnext... */
1092
1103
}
1093
1104
1094
1105
MemoryContextSwitchTo (oldcxt );
@@ -1101,8 +1112,8 @@ SearchSysCache(struct catcache * cache,
1101
1112
cache -> busy = false;
1102
1113
1103
1114
/* ----------------
1104
- * scan is complete. if tup is valid, we copy it and add the copy to
1105
- * the cache.
1115
+ * scan is complete. if tup is valid, we can add it to the cache.
1116
+ * note we have already copied it into the cache memory context .
1106
1117
* ----------------
1107
1118
*/
1108
1119
if (HeapTupleIsValid (ntp ))
@@ -1168,6 +1179,7 @@ SearchSysCache(struct catcache * cache,
1168
1179
heap_close (relation , AccessShareLock );
1169
1180
1170
1181
MemoryContextSwitchTo (oldcxt );
1182
+
1171
1183
return ntp ;
1172
1184
}
1173
1185
0 commit comments