Skip to content

Instantly share code, notes, and snippets.

@diegostamigni
Created January 21, 2013 10:59
Show Gist options
  • Save diegostamigni/4585283 to your computer and use it in GitHub Desktop.
Save diegostamigni/4585283 to your computer and use it in GitHub Desktop.
memagent.h used in Viron.
#ifndef __MEMAGENT_H
#define __MEMAGENT_H
#include <stdarg.h>
#include <stdlib.h>
#include <sys/conf.h>
// safe free with the checks if ptr exist
// before cleaning
static inline void safefree(void *ptr) {
if (ptr) return free(ptr);
}
// dealloc takes args as parameters, and dealloc those
// be careful by using this function
static inline void dealloc(void *args, ...) {
va_list p; va_start(p, args);
for (void *v = args; v; v = va_arg(p, void *))
safefree(v);
va_end(p);
}
// release x long size
static inline void release(void **x, size_t size) {
for (register int i = 0; i < size; i++)
safefree(*(x+i));
}
#endif /* MEMAGENT_H */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment