Re: POC: converting Lists into arrays - Mailing list pgsql-hackers

From Oleksandr Shulgin
Subject Re: POC: converting Lists into arrays
Date
Msg-id CACACo5QTvn7JbtJUBXtfb-p3jA6c0pJUk_-4BOHFqokok6m3Rg@mail.gmail.com
Whole thread Raw
In response to Re: POC: converting Lists into arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: POC: converting Lists into arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Jul 2, 2019 at 1:27 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

So I think this is a win, and attached is v7.

Not related to the diff v6..v7, but shouldn't we throw additionally a memset() with '\0' before calling pfree():

+        ListCell   *newelements;
+
+        newelements = (ListCell *)
+            MemoryContextAlloc(GetMemoryChunkContext(list),
+                               new_max_len * sizeof(ListCell));
+        memcpy(newelements, list->elements,
+               list->length * sizeof(ListCell));
+        pfree(list->elements);
+        list->elements = newelements;

Or is this somehow ensured by debug pfree() implementation or does it work differently together with Valgrind?

Otherwise it seems that the calling code can still be hanging onto a list element from a freed chunk and (rather) happily accessing it, as opposed to almost ensured crash if that is zeroed before returning from enlarge_list().

Cheers,
--
Alex

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Cache lookup errors with functions manipulation object addresses
Next
From: Michael Paquier
Date:
Subject: Re: Replacing the EDH SKIP primes