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

Commit a844c29

Browse files
committed
Prevent memory leaks in parseRelOptions().
parseRelOptions() tended to leak memory in the caller's context. Most of the time this doesn't really matter since the caller's context is at most query-lifespan, and the function won't be invoked very many times. However, when testing with CLOBBER_CACHE_RECURSIVELY, the same relcache entry can get rebuilt a *lot* of times in one query, leading to significant intraquery memory bloat if it has any reloptions. Noted while investigating a related report from Tomas Vondra. In passing, get rid of some Asserts that are redundant with the one done by deconstruct_array(). As with other patches to avoid leaks in CLOBBER_CACHE testing, it doesn't really seem worth back-patching this.
1 parent ab8c84d commit a844c29

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/backend/access/common/reloptions.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,6 @@ transformRelOptions(Datum oldOptions, List *defList, char *namspace,
620620
int noldoptions;
621621
int i;
622622

623-
Assert(ARR_ELEMTYPE(array) == TEXTOID);
624-
625623
deconstruct_array(array, TEXTOID, -1, false, 'i',
626624
&oldoptions, NULL, &noldoptions);
627625

@@ -777,8 +775,6 @@ untransformRelOptions(Datum options)
777775

778776
array = DatumGetArrayTypeP(options);
779777

780-
Assert(ARR_ELEMTYPE(array) == TEXTOID);
781-
782778
deconstruct_array(array, TEXTOID, -1, false, 'i',
783779
&optiondatums, NULL, &noptions);
784780

@@ -912,14 +908,10 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
912908
/* Done if no options */
913909
if (PointerIsValid(DatumGetPointer(options)))
914910
{
915-
ArrayType *array;
911+
ArrayType *array = DatumGetArrayTypeP(options);
916912
Datum *optiondatums;
917913
int noptions;
918914

919-
array = DatumGetArrayTypeP(options);
920-
921-
Assert(ARR_ELEMTYPE(array) == TEXTOID);
922-
923915
deconstruct_array(array, TEXTOID, -1, false, 'i',
924916
&optiondatums, NULL, &noptions);
925917

@@ -959,6 +951,11 @@ parseRelOptions(Datum options, bool validate, relopt_kind kind,
959951
errmsg("unrecognized parameter \"%s\"", s)));
960952
}
961953
}
954+
955+
/* It's worth avoiding memory leaks in this function */
956+
pfree(optiondatums);
957+
if (((void *) array) != DatumGetPointer(options))
958+
pfree(array);
962959
}
963960

964961
*numrelopts = numoptions;

0 commit comments

Comments
 (0)