Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=xbdmenu.git;a=commitdiff;h=9f4eedc4439d84a56489592d1468a8d9e9af2640

commit 9f4eedc4439d84a56489592d1468a8d9e9af2640
Author: James Buren <[email protected]>
Date:   Tue Mar 10 19:30:32 2009 -0500

mem.c
* initial draft

diff --git a/mem.c b/mem.c
new file mode 100644
index 0000000..94a0cb9
--- /dev/null
+++ b/mem.c
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static unsigned int rc;
+
+/* reference counting wrapper for malloc() */
+extern void *zmalloc(size_t size)
+{
+       void *ptr = malloc(size);
+       if(ptr==NULL)
+       {
+               printf("Aborting due to malloc() failure.\n");
+               exit(EXIT_FAILURE);
+       }
+       ++rc;
+       return(ptr);
+}
+
+/* initialization wrapper for zmalloc() */
+extern void *zmalloci(size_t size)
+{
+       void *ptr = zmalloc(size);
+       memset(ptr,0,size);
+       return(ptr);
+}
+
+/* reference counting wrapper for free() */
+extern void zfree(void *ptr)
+{
+       if(ptr==NULL)
+               printf("Invalid pointer passed to zfree().\n");
+       else
+       {
+               free(ptr);
+               --rc;
+       }
+}
+
+/* cleanup global variables */
+extern void cleanup(void)
+{
+       if(rc>0)
+               printf("Reference count of objects not freed: %d\n",rc);
+}
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to