After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 693678 - remove pointless NULL checks
remove pointless NULL checks
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-02-12 20:52 UTC by Dan Winship
Modified: 2013-02-13 18:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
all: remove pointless NULL checks (23.24 KB, patch)
2013-02-12 20:52 UTC, Dan Winship
committed Details | Review
all: remove more pointless NULL checks (101.45 KB, patch)
2013-02-12 20:52 UTC, Dan Winship
committed Details | Review

Description Dan Winship 2013-02-12 20:52:23 UTC
see patches
Comment 1 Dan Winship 2013-02-12 20:52:25 UTC
Created attachment 235815 [details] [review]
all: remove pointless NULL checks

g_malloc(), etc, never return NULL, by API contract. Likewise, by
extension, no other glib function ever returns NULL due to lack of
memory. So remove lots of unnecessary checks (the vast majority of
which would have immediately crashed had they ever run anyway, since
g_set_error(), g_warning(), and nm_log_*() all need to allocate
memory).
Comment 2 Dan Winship 2013-02-12 20:52:28 UTC
Created attachment 235816 [details] [review]
all: remove more pointless NULL checks

GObject creation cannot normally fail, except for types that implement
GInitable and take a GError in their _new() method. Some NM types
override constructor() and return NULL in some cases, but these
generally only happen in the case of programmer error (eg, failing to
set a mandatory property), and so crashing is reasonable (and most
likely inevitable anyway).

So, remove all NULL checks after calls to g_object_new() and its
myriad wrappers.
Comment 3 Jiri Klimes 2013-02-13 16:23:44 UTC
Review of attachment 235815 [details] [review]:

Looks good. It helps to clean-up a code a lot.
If a NULL is not returned, it doesn't make sense to check it.

One philosophical remark though. Even if it is nice to type ptr = g_malloc0 (10);
and don't care about possible failures, I don't think that's a good thing for glib
or any other library just to crash/quit on no-mem. It takes away the flexibility from the library
users on what to do on a failure. I know the application will most probably exit anyway,
but it can do it more gracefully. I know we do not make space-ship applications, fortunately :),
but yet.
Comment 4 Jiri Klimes 2013-02-13 16:30:48 UTC
Review of attachment 235816 [details] [review]:

Looks good. Just remove tools/generate-settings-spec that crept into the commit.
Comment 5 Dan Winship 2013-02-13 16:55:08 UTC
(In reply to comment #3)
> One philosophical remark though. Even if it is nice to type ptr = g_malloc0
> (10);
> and don't care about possible failures, I don't think that's a good thing for
> glib
> or any other library just to crash/quit on no-mem. It takes away the
> flexibility from the library
> users on what to do on a failure.

Shrug. Dealing with out-of-memory gracefully is MUCH harder than people imagine, and no one ever tests their out-of-memory-handling code either, so it almost certainly doesn't actually work (eg, all those g_set_error/g_warning/nm_log calls in NM). http://blog.ometer.com/2008/02/04/out-of-memory-handling-d-bus-experience/ is a good discussion of the pros/cons.

(And anyway, on Linux, the default configuration is for malloc() to overcommit [ie, never return NULL] and then have the kernel oom killer come out if you run out of memory.)
Comment 6 Dan Winship 2013-02-13 18:39:22 UTC
Attachment 235815 [details] pushed as d04f286 - all: remove pointless NULL checks
Attachment 235816 [details] pushed as 08f0446 - all: remove more pointless NULL checks