This patch contains my other two previous patches:

   - [PATCH] Fix eina mempool leak, init error handling, remove consumed
   TODO msg
   - [PATCH] Add checks to eina_module_new

Also fixes the build error with --disable-magic-debug.


-- 
André Dieb Martins

Embedded Systems and Pervasive Computing Lab (Embedded)
Electrical Engineering Department (DEE)
Center of Electrical Engineering and Informatics (CEEI)
Federal University of Campina Grande (UFCG)

Blog: http://genuinepulse.blogspot.com/
Index: src/include/eina_magic.h
===================================================================
--- src/include/eina_magic.h	(revision 40917)
+++ src/include/eina_magic.h	(working copy)
@@ -52,8 +52,8 @@
 #define eina_magic_string_get(Magic)                  (NULL)
 #define eina_magic_string_set(Magic, Magic_Name)      ((void) 0)
 #define eina_magic_fail(d, m, req_m, file, fnx, line) ((void) 0)
-#define eina_magic_string_init()   do {} while(0)
-#define eina_magic_string_shutdown() do {} while(0)
+#define eina_magic_string_init()   ((int) 1)
+#define eina_magic_string_shutdown() ((int) 0)
 
 #endif
 
Index: src/lib/eina_mempool.c
===================================================================
--- src/lib/eina_mempool.c	(revision 40917)
+++ src/lib/eina_mempool.c	(working copy)
@@ -123,8 +123,16 @@
 	{
 		char *path;
 
-		eina_hash_init();
-		eina_module_init();
+		if (!eina_hash_init())
+		  {
+		     fprintf(stderr, "Could not initialize eina hash module.\n");
+		     return 0;
+		  }
+		if (!eina_module_init())
+		  {
+		     fprintf(stderr, "Could not initialize eina module module.\n");
+		     goto module_init_error;
+		  }
 
 		EINA_ERROR_NOT_MEMPOOL_MODULE = eina_error_msg_register("Not a memory pool module.");
 		_backends = eina_hash_string_superfast_new(NULL);
@@ -147,7 +155,8 @@
 		if (!_modules)
 		{
 			EINA_ERROR_PERR("ERROR: no mempool modules able to be loaded.\n");
-			abort();
+			eina_hash_free(_backends);
+			goto mempool_init_error;
 		}
 		eina_module_list_load(_modules);
 		/* builtin backends */
@@ -165,6 +174,14 @@
 #endif
 	}
 	return ++_init_count;
+
+	mempool_init_error:
+	   eina_module_shutdown();
+	module_init_error:
+	   eina_hash_shutdown();
+
+	return 0;
+
 }
 
 /**
@@ -190,9 +207,15 @@
 	ememoa_fixed_shutdown();
 #endif
 	/* dynamic backends */
-	eina_module_list_unload(_modules);
+	eina_module_list_delete(_modules);
+	if (_modules)
+	   eina_array_free(_modules);
+
 	eina_module_shutdown();
-	/* TODO delete the _modules list */
+
+	if (_backends)
+	   eina_hash_free(_backends);
+
 	eina_hash_shutdown();
 	return 0;
 }
Index: src/lib/eina_module.c
===================================================================
--- src/lib/eina_module.c	(revision 40917)
+++ src/lib/eina_module.c	(working copy)
@@ -28,6 +28,7 @@
 #include <sys/types.h>
 #include <dirent.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #ifdef HAVE_ALLOCA_H
 # include <alloca.h>
@@ -260,11 +261,25 @@
 EAPI Eina_Module * eina_module_new(const char *file)
 {
 	Eina_Module *m;
+	struct stat stat_info;
 
 	EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
-	/* TODO check that the file exists */
 
+	if (stat(file, &stat_info) != 0)
+	  {
+	     // Could not retrieve information about the file
+	     eina_error_set(EINA_ERROR_WRONG_MODULE);
+	     return NULL;
+	  }
+
 	m = malloc(sizeof(Eina_Module));
+
+	if (!m)
+	  {
+	     eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
+	     return NULL;
+	  }
+	
 	/* TODO add the magic */
 	m->file = strdup(file);
 	m->ref = 0;
Index: src/lib/eina_error.c
===================================================================
--- src/lib/eina_error.c	(revision 40917)
+++ src/lib/eina_error.c	(working copy)
@@ -530,7 +530,6 @@
 	{
 		char *level;
 		/* TODO register the eina's basic errors */
-		/* TODO load the environment variable for getting the log level */
 		if ((level = getenv("EINA_ERROR_LEVEL")))
 		{
 			_error_level = atoi(level);
------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises 
looking to deploy the next generation of Solaris that includes the latest 
innovations from Sun and the OpenSource community. Download a copy and 
enjoy capabilities such as Networking, Storage and Virtualization. 
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to