From 748cf8946537e0c199cbf2f19cdc582001ea8232 Mon Sep 17 00:00:00 2001
From: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira@nokia.com>
Date: Fri, 25 Mar 2011 16:06:15 +0200
Subject: om: Fix potential memory leak in init_om.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira@nokia.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Backported-to-NX-by: Ulrich Sibiller <uli42@gmx.de>
---
 nx-X11/lib/X11/omGeneric.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/nx-X11/lib/X11/omGeneric.c b/nx-X11/lib/X11/omGeneric.c
index e54b27c29..dbddc8415 100644
--- a/nx-X11/lib/X11/omGeneric.c
+++ b/nx-X11/lib/X11/omGeneric.c
@@ -2094,22 +2094,24 @@ init_om(
     if (required_list == NULL)
 	return False;
 
-    bufptr = (char *) Xmalloc(length);
-    if (bufptr == NULL) {
-	Xfree(required_list);
-	return False;
-    }
-
     om->core.required_charset.charset_list = required_list;
     om->core.required_charset.charset_count = gen->data_num;
 
     count = gen->data_num;
     data = gen->data;
 
-    for ( ; count-- > 0; data++) {
-	strcpy(bufptr, data->font_data->name);
-	*required_list++ = bufptr;
-	bufptr += strlen(bufptr) + 1;
+    if (count > 0) {
+	bufptr = (char *) Xmalloc(length);
+	if (bufptr == NULL) {
+	    Xfree(required_list);
+	    return False;
+	}
+
+	for ( ; count-- > 0; data++) {
+	    strcpy(bufptr, data->font_data->name);
+	    *required_list++ = bufptr;
+	    bufptr += strlen(bufptr) + 1;
+	}
     }
 
     /* orientation list */
-- 
cgit v1.2.3