Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)

From: Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>
To: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Fix ouside scope t_ctid (ItemPointerData)
Date: 2020-05-14 22:23:53
Message-ID: E90F5F90-D39B-4C18-8DAE-0D1B38E09011@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On May 14, 2020, at 11:34 AM, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com> wrote:
>
> htup->t_ctid = target_tid;
> htup->t_ctid = newtid;
> Both target_tid and newtid are local variable, whe loss scope, memory is garbage.

Ok, thanks for the concrete example of what is bothering you.

In htup_details, I see that struct HeapTupleHeaderData has a field named t_ctid of type struct ItemPointerData. I also see in heapam that target_tid is of type ItemPointerData. The

htup->t_ctid = target_tid

copies the contents of target_tid. By the time target_tid goes out of scope, the contents are already copied. I would share your concern if t_ctid were of type ItemPointer (aka ItemPointerData *) and the code said

htup->t_ctid = &target_tid

but it doesn't say that, so I don't see the issue.

Also in heapam, I see that newtid is likewise of type ItemPointerData, so the same logic applies. By the time newtid goes out of scope, its contents have already been copied into t_ctid, so there is no problem.

But maybe you know all that and are just complaining that the name "ItemPointerData" sounds like a pointer rather than a struct? I'm still unclear whether you believe this is a bug, or whether you just don't like the naming that is used.


Mark Dilger
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2020-05-14 22:47:29 Re: SEQUENCE values (duplicated) in some corner cases when crash happens
Previous Message Jeremy Schneider 2020-05-14 22:09:28 Re: SEQUENCE values (duplicated) in some corner cases when crash happens