Plain strdup() in frontend code

Started by Daniel Gustafssonalmost 7 years ago5 messageshackers
Jump to latest
#1Daniel Gustafsson
daniel@yesql.se

Reading code I noticed that we in a few rare instances use strdup() in frontend
utilities instead of pg_strdup(). Is there a reason for not using pg_strdup()
consistently as per the attached patch?

cheers ./daniel

Attachments:

frontend_strdup.patchapplication/octet-stream; name=frontend_strdup.patchDownload+11-14
#2Michael Paquier
michael@paquier.xyz
In reply to: Daniel Gustafsson (#1)
Re: Plain strdup() in frontend code

On Mon, Apr 29, 2019 at 11:47:27AM +0000, Daniel Gustafsson wrote:

Reading code I noticed that we in a few rare instances use strdup() in frontend
utilities instead of pg_strdup(). Is there a reason for not using pg_strdup()
consistently as per the attached patch?

I think that it is good practice to encourage its use, so making
things more consistent is a good idea. While on it, we could also
switch psql's do_lo_import() which uses a malloc() to
pg_malloc_extended() with MCXT_ALLOC_NO_OOM. GetPrivilegesToDelete()
in pg_ctl also has an instance of malloc() with a similar failure
mode.
--
Michael

#3Daniel Gustafsson
daniel@yesql.se
In reply to: Michael Paquier (#2)
Re: Plain strdup() in frontend code

On Monday, April 29, 2019 3:01 PM, Michael Paquier <michael@paquier.xyz> wrote:

On Mon, Apr 29, 2019 at 11:47:27AM +0000, Daniel Gustafsson wrote:

Reading code I noticed that we in a few rare instances use strdup() in frontend
utilities instead of pg_strdup(). Is there a reason for not using pg_strdup()
consistently as per the attached patch?

I think that it is good practice to encourage its use, so making
things more consistent is a good idea. While on it, we could also
switch psql's do_lo_import() which uses a malloc() to
pg_malloc_extended() with MCXT_ALLOC_NO_OOM. GetPrivilegesToDelete()
in pg_ctl also has an instance of malloc() with a similar failure
mode.

Good point, I've updated the patch to include those as well.

cheers ./daniel

Attachments:

frontend_strdup-v2.patchapplication/octet-stream; name=frontend_strdup-v2.patchDownload+14-16
#4Michael Paquier
michael@paquier.xyz
In reply to: Daniel Gustafsson (#3)
Re: Plain strdup() in frontend code

On Mon, Apr 29, 2019 at 01:35:12PM +0000, Daniel Gustafsson wrote:

Good point, I've updated the patch to include those as well.

I have been reviewing this patch, and the change in pg_waldump is
actually a good thing, as we could finish with a crash if strdup()
returns NULL as the pointer gets directly used, and there would be an
assertion failure in open_file_in_directory().

parseAclItem() in dumputils.c gets changed so as we would not return
false on OOM anymore. I think that the current code is a bug as
parseAclItem() should return false to the caller only on a parsing
error so the caller can get confused between the OOM on strdup() and a
parsing problem.

In short, as presented, the patch looks acceptable to me. Are there
any objections to apply it on HEAD?
--
Michael

#5Michael Paquier
michael@paquier.xyz
In reply to: Michael Paquier (#4)
Re: Plain strdup() in frontend code

On Tue, Apr 30, 2019 at 10:23:51AM +0900, Michael Paquier wrote:

In short, as presented, the patch looks acceptable to me. Are there
any objections to apply it on HEAD?

And committed.
--
Michael