Bug 41048

Summary: can crash on failed realloc; cannot be forced to crash on all failed mallocs
Product: dbus Reporter: Simon McVittie <smcv>
Component: coreAssignee: Simon McVittie <smcv>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: enhancement    
Priority: medium CC: hp
Version: 1.4.xKeywords: patch
Hardware: Other   
OS: All   
URL: http://cgit.freedesktop.org/~smcv/dbus/log/?h=14-malloc-cannot-fail-41048
Whiteboard:
i915 platform: i915 features:
Attachments: [1/2] dbus_realloc: don't crash if realloc() returns NULL while using guards
[2/2] dbus-memory: add optional checking for system malloc() (etc.) failing

Description Simon McVittie 2011-09-20 11:03:27 UTC
libdbus tries to behave in a way suitable for a core system service, for instance by surviving (and rolling back a transaction) if memory allocators return NULL.

A bug and an enhancement in this direction:

* One call to realloc() is not checked, so libdbus crashes if it returns NULL.
  My first patch checks it.

* To debug memory issues, it would be useful to be able to put libdbus in
  a GLib-like mode where malloc failures are fatal, particularly when combined
  with a small rlimit. My second patch adds this; for the moment it depends
  on DBUS_BUILD_TESTS.
Comment 1 Simon McVittie 2011-09-20 11:04:26 UTC
Created attachment 51416 [details] [review]
[1/2] dbus_realloc: don't crash if realloc() returns NULL while using guards
Comment 2 Simon McVittie 2011-09-20 11:04:48 UTC
Created attachment 51417 [details] [review]
[2/2] dbus-memory: add optional checking for system malloc() (etc.) failing

If tests are enabled and DBUS_MALLOC_CANNOT_FAIL is set, abort on system
malloc() failures (as GLib's g_malloc does). This can be used in
conjunction with a resource limit, to turn runaway memory leaks into a
debuggable core-dump.
Comment 3 Guillaume Desmottes 2012-02-20 05:22:51 UTC
Comment on attachment 51416 [details] [review]
[1/2] dbus_realloc: don't crash if realloc() returns NULL while using guards

Review of attachment 51416 [details] [review]:
-----------------------------------------------------------------

++
Comment 4 Guillaume Desmottes 2012-02-20 05:50:07 UTC
Comment on attachment 51417 [details] [review]
[2/2] dbus-memory: add optional checking for system malloc() (etc.) failing

Review of attachment 51417 [details] [review]:
-----------------------------------------------------------------

++
Comment 5 Simon McVittie 2012-02-21 07:15:10 UTC
Fixed in git for 1.5.10, thanks. I didn't merge this for 1.4 in the end.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.