Skip site navigation (1) Skip section navigation (2)

Re: pg_malloc() versus malloc(0)

From: Dimitri Fontaine <dimitri(at)2ndQuadrant(dot)fr>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: pg_malloc() versus malloc(0)
Date: 2012-10-01 14:30:01
Message-ID: m2pq52uuxi.fsf@2ndQuadrant.fr (view raw or flat)
Thread:
Lists: pgsql-hackers
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
> Namely, that on platforms where malloc(0) returns NULL instead of
> a pointer to a zero-size block, pg_malloc thinks it's a failure
> and aborts the program.

What's the use case for malloc(0) anyway?

> 1. Teach pg_malloc not to complain if result == NULL and size == 0.

What about not calling malloc at all in such places? Well I guess what
you want is for the pg_malloc() API to be able to never return NULL…

> 2. Before the malloc call, have it replace size == 0 with size = 1.

As I don't understand the need to malloc 0 byte I would think that's ok
as a way to simplify code…

Regards,
-- 
Dimitri Fontaine
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2012-10-01 14:36:52
Subject: Re: Extending range of to_tsvector et al
Previous:From: Magnus HaganderDate: 2012-10-01 14:22:14
Subject: Re: Hash id in pg_stat_statements

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group