[unixODBC-dev] Handling out-of-memory

Heikki Linnakangas hlinnakangas at vmware.com
Thu Feb 28 08:04:14 GMT 2013


Hi,

While working on the PostgreSQL driver, I bumped into two little bugs in 
handling out-of-memory situation. Patch attached. It's probably 
self-evident from the patch what the bugs are, but I'll explain anyway:

1. In __post_internal_error_ex, check for NULL return from malloc, and 
avoid some unnecessary allocations so that we don't need to handle the 
case that they fail. (In my test case, the reason that 
__post_internal_error_ex got called in the first place was that dlopen() 
failed with Out-of-Memory while loading the driver, so it's not 
surprising that those allocations failed too)

2. In __alloc_desc, there is a check for calloc returning NULL, but some 
of the initialization code was misplaced, and was being called on the 
NULL pointer anyway.

There are a lot more places where we don't check for malloc returning 
NULL, but fixing those two made my test case work. In the test case, I 
opened a large number of connections, and to induce the OOM condition, I 
ran it with a small "ulimit -v".

- Heikki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-oom-crash.patch
Type: text/x-diff
Size: 9228 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20130228/39b0b36c/attachment.bin>


More information about the unixODBC-dev mailing list