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

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



On Sat, Jun 10, 2006 at 07:21:10PM +0200, Kim Woelders wrote:
// 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.

Well, first of all, I've have heard/read, that if u start using
malloc/calloc/etc, then its better to use it every were. For me it is
better to have a null pointer rather than to have an unknown thing that
we can get when using malloc.

Anyway, this small fix prevents my E to crash when a window, which has
argc >= 3, is closed.

The main point was to set argc=0 when malloc/calloc returns NULL.

Aleksej

// 
// /Kim
// 
// 
// 
// _______________________________________________
// enlightenment-devel mailing list
// enlightenment-devel@lists.sourceforge.net
// https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

-- 

Aleksej Struk
Master Degree Student
Free University of Bozen-Bolzano
Faculty of Computer Science
phone: +39-0471-061749
cell phone: +39-3204627049 +370-61278908
astruk@gmail.com alstruk@unibz.it - http://astruk.googlepages.com/home