remove unneeded pstrdup in fetch_table_list

From: "Hou, Zhijie" <houzj(dot)fnst(at)cn(dot)fujitsu(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: remove unneeded pstrdup in fetch_table_list
Date: 2021-01-13 02:40:54
Message-ID: 229fed2eb8c54c71a96ccb99e516eb12@G08CNEXMBPEKD05.g08.fujitsu.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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;
**

It may harm when there are a lot of tables are replicated.
So I try to fix this.

Best regards,
houzj

Attachment Content-Type Size
0001-remove-unneeded-pstrdup.patch application/octet-stream 865 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2021-01-13 03:08:30 Re: A failure of standby to follow timeline switch
Previous Message Edmund Horner 2021-01-13 02:37:50 Re: Tid scan improvements