From: | Michael Paquier <michael(dot)paquier(at)gmail(dot)com> |
---|---|
To: | PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Combinations of pg_strdup/free in pg_dump code |
Date: | 2016-03-28 13:42:28 |
Message-ID: | CAB7nPqQ0QAt4f4mTPrxizznS6rr-tGLB6o1xRQW8962U6mRR=A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi all,
While reading some code of pg_dump, I noticed that the following
pattern is heavily present:
lanname = pg_strdup(stuff)
free(lanname);
One example is for example that:
lanname = get_language_name(fout, transforminfo[i].trflang);
if (typeInfo && lanname)
appendPQExpBuffer(&namebuf, "%s %s",
typeInfo->dobj.name, lanname);
transforminfo[i].dobj.name = namebuf.data;
free(lanname);
And get_language_name() uses pg_strdup() to allocate the string freed here.
When pg_strdup or any pg-related allocation routines are called, I
think that we should use pg_free() and not free(). It does not matter
much in practice because pg_free() calls actually free() and the
latter per the POSIX spec should do nothing if the input pointer is
NULL (some version of SunOS that crash on that actually :p), but we
really had better be consistent in the calls done. Thoughts?
--
Michael
From | Date | Subject | |
---|---|---|---|
Next Message | Anastasia Lubennikova | 2016-03-28 13:45:28 | Re: WIP: Covering + unique indexes. |
Previous Message | Michael Paquier | 2016-03-28 13:28:01 | Re: Proposal: "Causal reads" mode for load balancing reads without stale data |