Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1beNMA-00073O-MF for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2016 14:16:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1beNM9-0007ry-Qf for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2016 14:16:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1beNKk-0006Fe-JU for pgsql-hackers@postgresql.org; Mon, 29 Aug 2016 14:14:42 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1beNKh-000317-GI for pgsql-hackers@postgresql.org; Mon, 29 Aug 2016 14:14:41 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2A3A621C249B; Mon, 29 Aug 2016 17:14:37 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from mail.postgrespro.ru ([127.0.0.1]) by localhost (mail.postgrespro.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EVTnwoHLNH2T; Mon, 29 Aug 2016 17:14:37 +0300 (MSK) Received: from localhost (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id DE7D721C2490; Mon, 29 Aug 2016 17:14:36 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1472480077; bh=JE0Jpmv5IIXgBq5hh8/6FOBG2EM5sDZzj4BRl1JCC8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=gli5EOYz6grMBuRWQOnS4/Y3VqbgmXTuDULHrmZfIaEJna9D0aJwv7rgO4BPNpw5f 7e5wsF6yW3CaIMRCi0lqmQki2YyWoWlXL9jyGA+HmBtuSg3IBjfIEWvnMopJFOaK2R qWc1n2gm+qW/2OV+yIXKtmKuK0B4jcigyNt7vZPc= Date: Mon, 29 Aug 2016 17:13:15 +0300 From: Aleksander Alekseev To: Michael Paquier Cc: Heikki Linnakangas , Tom Lane , PostgreSQL mailing lists Subject: Re: Missing checks when malloc returns NULL... Message-ID: <20160829141315.GB8340@e733> References: <7978.1466516782@sss.pgh.pa.us> <20160829130513.GA8340@e733> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="hQiwHBbRI9kgIhsi" Content-Disposition: inline In-Reply-To: <20160829130513.GA8340@e733> User-Agent: Mutt/1.6.1 (2016-04-27) X-Pg-Spam-Score: -3.5 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --hQiwHBbRI9kgIhsi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > 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 --hQiwHBbRI9kgIhsi Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="shmem.txt" ./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); --hQiwHBbRI9kgIhsi Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --hQiwHBbRI9kgIhsi--