Bug 9071 - libtalloc should have option to abort on out of memory conditions
libtalloc should have option to abort on out of memory conditions
Status: NEW
Product: TALLOC
Classification: Unclassified
Component: libtalloc
unspecified
All All
: P5 enhancement
: ---
Assigned To: Simo Sorce
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-07-29 11:17 UTC by nfxjfg
Modified: 2012-07-29 11:17 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nfxjfg 2012-07-29 11:17:08 UTC
talloc is a great way to manage memory in C. It's so good, that projects unrelated to Samba use it.

There is one downside: some programs like not to handle out of memory conditions, because being able to deal with them is not much worth considering the use cases, and would only complicate the program. But talloc expects callers to handle these conditions.

I suggest adding a function that allows making talloc to aborting on out of memory conditions. Something like:

   void talloc_set_out_of_memory_handler(void (*handler)(size_t size));

If the handler is NULL (the default), talloc will return NULL on failed allocations. Otherwise, the handler would be called with the size of the failed allocation. The handler then could print an error message and call abort().

This would allow users of libtalloc to set their preferred OOM policy, without requiring them to include modified private or statically linked copies of libtalloc. (I know at least one project, mplayer2, which includes an old, outdated and hacked copy of talloc possibly for this reason.)

One caveat of this solution is that there can be only one OOM policy at runtime. (Consider a project using both libtalloc and libsmbclient.)