unchecked malloc

Started by Qingqing Zhouover 20 years ago2 messages
#1Qingqing Zhou
zhouqq@cs.toronto.edu

There are several places in both backend and tools that forget to check the
return value of malloc(). For example(8.0.1),

backend/port/dynloader/beos.c/pg_dlopen()
backend/bootstrap/bootstrap.c/AddStr()
port/strdup.c/strdup()
bin/pg_dump/common.c/findParentsByOid()
...

I am thinking we should fix them. Basically we have two ways, one is to
define a pg_malloc() as psql already did, the other is to fix these places
one by one. I prefer the first method, since it hides the return value check
details in the function and less error proning. To report the "out of
memory" error, we should differenciate if ErrorContext is already set up.

Comments?

Regards,
Qingqing

#2Qingqing Zhou
zhouqq@cs.toronto.edu
In reply to: Qingqing Zhou (#1)
Re: unchecked malloc

"Tom Lane" <tgl@sss.pgh.pa.us> wrote

No, because you're thinking in terms of the backend environment, and
generally in the backend the answer to "when to use malloc directly"
is "never".

Well, except before MemoryContext mechanism is set up? For example, the
functions(e.g., GUC, vfd) used during bootstrap.

So are you suggesting we fix these place by place? This should be ok.

Regards,
Qingqing