GNOME Bugzilla – Bug 761959
[review] cleanup event_handler_recvmsgs() in nm-linux-platform.h [th/platform-recvmsgs-fixes-bgo761959]
Last modified: 2016-02-16 13:18:45 UTC
please review
> macros: add nm_auto_free macro Similar to gs_free to cleanup pointers with free(). Note that g_free() and free() cannot be used interchangably. I don't understand which is the practical difference between gs_free() and nm_auto_free(), can you please explain? The rest LGTM.
In many cases g_free/g_malloc uses free/malloc from libc and there is no difference. That is however not guaranteed and where it's not true, bad things will happen. Thus, if memory was allocated with malloc(), you must free it with free() or nm_auto_free -- not g_free() nor gs_free. See also: https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html It's important to match g_malloc() (and wrappers such as g_new()) with g_free(), g_slice_alloc() (and wrappers such as g_slice_new()) with g_slice_free(), plain malloc() with free(), and (if you're using C++) new with delete and new[] with delete[]. Otherwise bad things can happen, since these allocators may use different memory pools (and new/delete call constructors and destructors).
merged: https://cgit.freedesktop.org/NetworkManager/NetworkManager/commit/?id=433d4fed6ac8f30161d20c2f192019eb44e7a77c