If you are just looking for a unified way (without code duplication) to check if allocation was successful or not, please see the last segment of this post.
First of all boost is mainly a library for C++, therefor all of boost can't be used in C.
Writing your own Garbage Collector is not easy, especially in a language without true OOP (such as C). There are many implementations of garbage collectors available online, so instead of reinventing the wheel you could check out some of them.
If you are not going to use any of them, well.. at least they will provide you with some information regarding how the problem can be solved.
Depending on the project size you might be better of using valgrind looking for leaking data and then manage the memory allocation/release by yourself.
C has been around for many years, and a lot of developers have managed without a automatic garbage collector. Why shouldn't you be able to do the same?
Simple error checking on allocation (and abort on error)
#include <stdio.h> #include <stdlib.h> void* safe_alloc_check (void *p, size_t size) { if (p == NULL) { printf ("ERROR: Unable to allocate memory for %lu bytes!", size); exit (-1); } return p; } #define s_malloc(N) safe_alloc_check(malloc(N),N) #define s_calloc(C,N) safe_alloc_check(calloc(C,N),N) #define s_realloc(P,N) safe_alloc_check(realloc(P,N),N) ... int *p = s_malloc (sizeof (int));
malloc, and you havefree. What exactly do you want to encapsulate?