[12/16] om: Fix potential memory leak in init_om.

Submitted by Ander Conselvan de Oliveira on March 30, 2011, 8:12 p.m.

Details

Message ID 1301490729-22084-13-git-send-email-ander.conselvan-de-oliveira@nokia.com
State Accepted, archived
Commit d749948f9492fd9b61c74655a08e32c595e0e3a5
Headers show

Not browsing as part of any series.

Commit Message

Ander Conselvan de Oliveira March 30, 2011, 8:12 p.m.
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan-de-oliveira@nokia.com>
---
 modules/om/generic/omGeneric.c |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/modules/om/generic/omGeneric.c b/modules/om/generic/omGeneric.c
index ec2abc0..6088350 100644
--- a/modules/om/generic/omGeneric.c
+++ b/modules/om/generic/omGeneric.c
@@ -2121,22 +2121,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 */