gnome-keyring r1565 - in trunk: . egg



Author: nnielsen
Date: Fri Feb 13 18:32:47 2009
New Revision: 1565
URL: http://svn.gnome.org/viewvc/gnome-keyring?rev=1565&view=rev

Log:
Don't try and allocate 0 bytes when changing  allocator on an empty buffer.

Modified:
   trunk/ChangeLog
   trunk/egg/egg-buffer.c

Modified: trunk/egg/egg-buffer.c
==============================================================================
--- trunk/egg/egg-buffer.c	(original)
+++ trunk/egg/egg-buffer.c	Fri Feb 13 18:32:47 2009
@@ -116,23 +116,25 @@
 int
 egg_buffer_set_allocator (EggBuffer *buffer, EggBufferAllocator allocator)
 {
-	unsigned char *buf;
+	unsigned char *buf = NULL;
 	
 	if (!allocator)
 		allocator = DEFAULT_ALLOCATOR;
 	if (buffer->allocator == allocator)
 		return 1;
 	
-	/* Reallocate memory block using new allocator */
-	buf = (allocator) (NULL, buffer->allocated_len);
-	if (!buf)
-		return 0;
+	if (buffer->allocated_len) {
+		/* Reallocate memory block using new allocator */
+		buf = (allocator) (NULL, buffer->allocated_len);
+		if (buf == NULL)
+			return 0;
+		
+		/* Copy stuff into new memory */
+		memcpy (buf, buffer->buf, buffer->allocated_len);
+	}
 		
-	/* Copy stuff and free old memory */
-	memcpy (buf, buffer->buf, buffer->allocated_len);
-	
 	/* If old wasn't static, then free it */
-	if (buffer->allocator)
+	if (buffer->allocator && buffer->buf)
 		(buffer->allocator) (buffer->buf, 0);
 		
 	buffer->buf = buf;



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