Re: remove unneeded pstrdup in fetch_table_list

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: remove unneeded pstrdup in fetch_table_list
Date: 2021-01-13 06:10:33
Message-ID: CAA4eK1LBw7bhBLsXS1ozXW0rhwZqytq74j1riq2jJoVZniFHLg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jan 13, 2021 at 8:11 AM Hou, Zhijie <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com> wrote:
>
> Hi
>
> In function fetch_table_list, it get the table names from publicer and return a list of tablenames.
> When append the name to the list, it use the following code:
>
> **
> nspname = TextDatumGetCString(slot_getattr(slot, 1, &isnull));
> Assert(!isnull);
> relname = TextDatumGetCString(slot_getattr(slot, 2, &isnull));
> rv = makeRangeVar(pstrdup(nspname), pstrdup(relname), -1);
> tablelist = lappend(tablelist, rv);
> **
>
> the nspname and relname will be copied which seems unnecessary.
> Because nspame and relname is get from TextDatumGetCString.
> IMO, TextDatumGetCString returns a newly palloced string.
>
> **
> result = (char *) palloc(len + 1);
> memcpy(result, VARDATA_ANY(tunpacked), len);
> result[len] = '\0';
>
> if (tunpacked != t)
> pfree(tunpacked);
>
> return result;
> **
>

Your observation seems correct to me, though I have not tried to test
your patch.

--
With Regards,
Amit Kapila.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2021-01-13 06:33:26 Re: Single transaction in the tablesync worker?
Previous Message tsunakawa.takay@fujitsu.com 2021-01-13 06:01:34 RE: Disable WAL logging to speed up data loading