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.
This commit is contained in:
Thomas Haller 2016-02-12 15:43:30 +01:00
parent ad45d232fe
commit c66ee23f73
2 changed files with 11 additions and 1 deletions

View file

@ -41,6 +41,8 @@
/* always include these headers for our internal source files. */
#include <stdlib.h>
#include "nm-glib.h"
#include "nm-version.h"
#include "gsystem-local-alloc.h"

View file

@ -22,7 +22,15 @@
#ifndef __NM_MACROS_INTERNAL_H__
#define __NM_MACROS_INTERNAL_H__
#include "nm-default.h"
/********************************************************/
/**
* nm_auto_free:
*
* Call free() on a variable location when it goes out of scope.
*/
#define nm_auto_free __attribute__ ((cleanup(_nm_auto_free_impl)))
GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free)
/********************************************************/