pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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 16:05:14 +0300
Message-ID: <20160829130513.GA8340@e733> (raw)
In-Reply-To: <CAB7nPqSCxBWt7Q1dpFTekg-zDx_GZ-ELgEOfYJ47zrD8=v=yHg@mail.gmail.com>
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>
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?

-- 
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-hackers

Attachments:

calloc.txt (text/plain, 3.8K) download Looks like resource leak: ./src/backend/storage/buffer/localbuf.c: LocalBufferDescriptors = (BufferDesc *) calloc(nbufs, sizeof(BufferDesc)); ./src/backend/storage/buffer/localbuf.c: LocalBufferBlockPointers = (Block *) calloc(nbufs, sizeof(Block)); ./src/backend/storage/buffer/localbuf.c: LocalRefCount = (int32 *) calloc(nbufs, sizeof(int32)); ./src/backend/storage/buffer/localbuf.c- if (!LocalBufferDescriptors || !LocalBufferBlockPointers || !LocalRefCount) ./src/backend/storage/buffer/localbuf.c- ereport(FATAL, ./src/backend/storage/buffer/localbuf.c- (errcode(ERRCODE_OUT_OF_MEMORY), ./src/backend/storage/buffer/localbuf.c- errmsg("out of memory"))); ./src/backend/storage/buffer/localbuf.c- ./src/interfaces/libpq/fe-print.c- nTups = PQntuples(res); ./src/interfaces/libpq/fe-print.c: if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *)))) ./src/interfaces/libpq/fe-print.c- { ./src/interfaces/libpq/fe-print.c- fprintf(stderr, libpq_gettext("out of memory\n")); ./src/interfaces/libpq/fe-print.c- abort(); ./src/interfaces/libpq/fe-print.c- } ./src/interfaces/libpq/fe-print.c: if (!(fieldNotNum = (unsigned char *) calloc(nFields, 1))) ./src/interfaces/libpq/fe-print.c- { ./src/interfaces/libpq/fe-print.c- fprintf(stderr, libpq_gettext("out of memory\n")); ./src/interfaces/libpq/fe-print.c- abort(); ./src/interfaces/libpq/fe-print.c- } ./src/interfaces/libpq/fe-print.c: if (!(fieldMax = (int *) calloc(nFields, sizeof(int)))) ./src/interfaces/libpq/fe-print.c- { ./src/interfaces/libpq/fe-print.c- fprintf(stderr, libpq_gettext("out of memory\n")); ./src/interfaces/libpq/fe-print.c- abort(); ./src/interfaces/libpq/fe-print.c- } Two identical pieces of code: ./src/backend/bootstrap/bootstrap.c- scan = heap_beginscan_catalog(rel, 0, NULL); ./src/backend/bootstrap/bootstrap.c- i = 0; ./src/backend/bootstrap/bootstrap.c- while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL) ./src/backend/bootstrap/bootstrap.c- ++i; ./src/backend/bootstrap/bootstrap.c- heap_endscan(scan); ./src/backend/bootstrap/bootstrap.c: app = Typ = ALLOC(struct typmap *, i + 1); ./src/backend/bootstrap/bootstrap.c- while (i-- > 0) ./src/backend/bootstrap/bootstrap.c: *app++ = ALLOC(struct typmap, 1); ./src/backend/bootstrap/bootstrap.c- *app = NULL; ./src/backend/bootstrap/bootstrap.c- scan = heap_beginscan_catalog(rel, 0, NULL); ./src/backend/bootstrap/bootstrap.c- app = Typ; ./src/backend/bootstrap/bootstrap.c- while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL) ./src/backend/bootstrap/bootstrap.c- { ./src/backend/bootstrap/bootstrap.c- scan = heap_beginscan_catalog(rel, 0, NULL); ./src/backend/bootstrap/bootstrap.c- i = 0; ./src/backend/bootstrap/bootstrap.c- while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL) ./src/backend/bootstrap/bootstrap.c- ++i; ./src/backend/bootstrap/bootstrap.c- heap_endscan(scan); ./src/backend/bootstrap/bootstrap.c: app = Typ = ALLOC(struct typmap *, i + 1); ./src/backend/bootstrap/bootstrap.c- while (i-- > 0) ./src/backend/bootstrap/bootstrap.c: *app++ = ALLOC(struct typmap, 1); ./src/backend/bootstrap/bootstrap.c- *app = NULL; ./src/backend/bootstrap/bootstrap.c- scan = heap_beginscan_catalog(rel, 0, NULL); ./src/backend/bootstrap/bootstrap.c- app = Typ; ./src/backend/bootstrap/bootstrap.c- while ((tup = heap_getnext(scan, ForwardScanDirection)) != NULL) ./src/backend/bootstrap/bootstrap.c- {

view thread (33+ messages)  latest in thread

Message-ID: <20160829130513.GA8340@e733>
Permalink:  ../20160829130513.GA8340@e733/
Also on:    postgresql.org/message-id/20160829130513.GA8340@e733

 · 

reply

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: <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>

* 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