[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [E-devel] E CVS: libs/ecore sndev



Kim Woelders wrote:
Enlightenment CVS wrote:

Enlightenment CVS committal

Author  : sndev
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_x


Modified Files:
ecore_x_icccm.c

Log Message:

* use calloc instead of malloc
* set *argc = 0 if mem for the *argv cannot be allocated.

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_x/ecore_x_icccm.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -3 -r1.43 -r1.44
--- ecore_x_icccm.c	8 Jun 2006 20:03:42 -0000	1.43
+++ ecore_x_icccm.c	10 Jun 2006 16:54:36 -0000	1.44
@@ -752,8 +752,12 @@
   if (argc) *argc = c;
   if (argv)
     {
-	(*argv) = malloc(c);
-	if (!*argv) return;
+	(*argv) = calloc(c, sizeof(char *));
+	if (!*argv)
+ { + *argc = 0;
+	     return;
+	  }
	for (i = 0; i < c; i++)
	  (*argv)[i] = strdup(v[i]);
     }


Um.. There is not much point in using calloc here since the allocated area is filled entrirely with strdup pointers anyway. Not that this will cause a major performance hit though :) However, I assume you do want to fix that if calloc fails you'll get a memory leak from not freeing v.

I forgot to mention - I think I have seen cases where c is zero. I'm not sure malloc(0) always is legal. Also, I have seen cases where v[] elements are NULL, in which case strdup segv's.

/Kim