From: Aleksander Alekseev <a.alekseev@postgrespro.ru>
To: Michael Paquier <michael.paquier@gmail.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL mailing lists <pgsql-hackers@postgresql.org>
Subject: Re: Missing checks when malloc returns NULL...
Date: Mon, 29 Aug 2016 17:13:15 +0300
Message-ID: <20160829141315.GB8340@e733> (raw)
In-Reply-To: <20160829130513.GA8340@e733>
References: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com>
<7978.1466516782@sss.pgh.pa.us>
<CAB7nPqRRR8mnM9kbGObV2tzP-BpmLotiKyVBPbY2bxjuAyeCpw@mail.gmail.com>
<d4b09f6b-06b9-2678-a0f8-714e3468b9eb@iki.fi>
<CAB7nPqQhEF854DuLPaqpx+FfrY3YEcqYTVa12YKXMk_ayCtqqQ@mail.gmail.com>
<CAB7nPqSCxBWt7Q1dpFTekg-zDx_GZ-ELgEOfYJ47zrD8=v=yHg@mail.gmail.com>
<20160829130513.GA8340@e733>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
> Hello, Michael
>
> > I don't know how you did it, but this email has visibly broken the
> > original thread. Did you change the topic name?
>
> I'm very sorry for this. I had no local copy of this thread. So I wrote a
> new email with the same subject hoping it will be OK. Apparently right
> In-Reply-To header is also required.
>
> > if (prodesc->user_proname == NULL || prodesc->internal_proname == NULL)
> > + {
> > + free(prodesc);
>
> I think that prodesc->user_proname and prodesc->internal_proname should
> also be freed if they are not NULL's.
>
> > By the way maybe someone knows other procedures besides malloc, realloc
> > and strdup that require special attention?
>
> I recalled that there is also calloc(). I've found four places that use
> calloc() and look suspicious to me (see attachment). What do you think -
> are these bugs or not?
I've just realized that there is also malloc-compatible ShmemAlloc().
Apparently it's return value sometimes is not properly checked too. See
attachment.
--
Best regards,
Aleksander Alekseev
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:shmem.txt (text/plain, 2.2K) download
./src/backend/access/transam/slru.c- /* Initialize LWLocks */
./src/backend/access/transam/slru.c: shared->buffer_locks = (LWLockPadded *) ShmemAlloc(sizeof(LWLockPadded) * nslots);
./src/backend/access/transam/slru.c-
./src/backend/access/transam/slru.c- Assert(strlen(name) + 1 < SLRU_MAX_NAME_LENGTH);
./src/backend/access/transam/slru.c- strlcpy(shared->lwlock_tranche_name, name, SLRU_MAX_NAME_LENGTH);
./src/backend/access/transam/slru.c- shared->lwlock_tranche_id = tranche_id;
./src/backend/access/transam/slru.c- shared->lwlock_tranche.name = shared->lwlock_tranche_name;
./src/backend/postmaster/postmaster.c-void
./src/backend/postmaster/postmaster.c-ShmemBackendArrayAllocation(void)
./src/backend/postmaster/postmaster.c-{
./src/backend/postmaster/postmaster.c- Size size = ShmemBackendArraySize();
./src/backend/postmaster/postmaster.c-
./src/backend/postmaster/postmaster.c: ShmemBackendArray = (Backend *) ShmemAlloc(size);
./src/backend/postmaster/postmaster.c- /* Mark all slots as empty */
./src/backend/postmaster/postmaster.c- memset(ShmemBackendArray, 0, size);
./src/backend/postmaster/postmaster.c-}
./src/backend/storage/ipc/shmem.c- ShmemVariableCache = (VariableCache)
./src/backend/storage/ipc/shmem.c: ShmemAlloc(sizeof(*ShmemVariableCache));
./src/backend/storage/ipc/shmem.c- memset(ShmemVariableCache, 0, sizeof(*ShmemVariableCache));
./src/backend/storage/ipc/shmem.c-}
./src/backend/storage/lmgr/lwlock.c- /* Allocate space */
./src/backend/storage/lmgr/lwlock.c: ptr = (char *) ShmemAlloc(spaceLocks);
./src/backend/storage/lmgr/lwlock.c-
./src/backend/storage/lmgr/lwlock.c- /* Leave room for dynamic allocation of tranches */
./src/backend/storage/lmgr/lwlock.c- ptr += sizeof(int);
./src/backend/storage/lmgr/proc.c: pgxacts = (PGXACT *) ShmemAlloc(TotalProcs * sizeof(PGXACT));
./src/backend/storage/lmgr/proc.c- MemSet(pgxacts, 0, TotalProcs * sizeof(PGXACT));
./src/backend/storage/lmgr/proc.c- /* Create ProcStructLock spinlock, too */
./src/backend/storage/lmgr/proc.c: ProcStructLock = (slock_t *) ShmemAlloc(sizeof(slock_t));
./src/backend/storage/lmgr/proc.c- SpinLockInit(ProcStructLock);
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: a.alekseev@postgrespro.ru, michael.paquier@gmail.com, hlinnaka@iki.fi, tgl@sss.pgh.pa.us
Subject: Re: Missing checks when malloc returns NULL...
In-Reply-To: <20160829141315.GB8340@e733>
References: <CAB7nPqRu07Ot6iht9i9KRfYLpDaF2ZuUv5y_+72uP23ZAGysRg@mail.gmail.com> <7978.1466516782@sss.pgh.pa.us> <CAB7nPqRRR8mnM9kbGObV2tzP-BpmLotiKyVBPbY2bxjuAyeCpw@mail.gmail.com> <d4b09f6b-06b9-2678-a0f8-714e3468b9eb@iki.fi> <CAB7nPqQhEF854DuLPaqpx+FfrY3YEcqYTVa12YKXMk_ayCtqqQ@mail.gmail.com> <CAB7nPqSCxBWt7Q1dpFTekg-zDx_GZ-ELgEOfYJ47zrD8=v=yHg@mail.gmail.com> <20160829130513.GA8340@e733> <20160829141315.GB8340@e733>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox