Re: valgrind error in subscription code

From: Petr Jelinek <petr(dot)jelinek(at)2ndquadrant(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, Petr Jelinek <petr(at)2ndquadrant(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: valgrind error in subscription code
Date: 2017-04-23 21:17:58
Message-ID: 15dcb113-48ff-cb8b-9662-2946ba4cd8f4@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 22/04/17 21:16, Andres Freund wrote:
> Hi,
>
> On 2017-04-22 21:08:18 +0200, Petr Jelinek wrote:
>> Thanks, here is patch to fix that - I also removed the individual
>> settings of everything to NULL/0/InvalidOid etc and just replaced it all
>> with memset.
>
> Cool.
>
>> diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c
>> index 875a081..5bc54dd 100644
>> --- a/src/backend/replication/logical/relation.c
>> +++ b/src/backend/replication/logical/relation.c
>> @@ -141,19 +141,10 @@ logicalrep_relmap_free_entry(LogicalRepRelMapEntry *entry)
>> pfree(remoterel->attnames);
>> pfree(remoterel->atttyps);
>> }
>> - remoterel->attnames = NULL;
>> - remoterel->atttyps = NULL;
>> -
>> bms_free(remoterel->attkeys);
>> - remoterel->attkeys = NULL;
>>
>> if (entry->attrmap)
>> pfree(entry->attrmap);
>> -
>
> Btw, I think it's a good pattern to zero things like attrmap after
> freeing. Based on a minute of looking it's unclear to me if
> logicalrep_relmap_update() could be called again, if e.g. one of the
> pallocs after the logicalrep_relmap_free_entry() errors out. I think
> you essentially addressed that with the memset, so that's good.
>

Yes, memset is called immediately after logicalrep_relmap_free_entry()
which is why I found it redundant to set things to NULL there. We could
put the memset directly inside logicalrep_relmap_free_entry() and the
call either logicalrep_relmap_free_entry() or memset in the caller if
that would make you feel better about it.

--
Petr Jelinek http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2017-04-23 22:29:04 TAP tests - installcheck vs check
Previous Message Simon Riggs 2017-04-23 21:15:36 Re: StandbyRecoverPreparedTransactions recovers subtrans links incorrectly