[PATCH resend 2/4] On realloc failure, free font_path_string instead of leaking it

Alan Coopersmith alan.coopersmith at oracle.com
Tue Jan 28 20:27:50 PST 2014


Flagged by cppcheck 1.62:
[dix/dixfonts.c:1792]: (error) Common realloc mistake:
 'font_path_string' nulled but not freed upon failure

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 dix/dixfonts.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 341ca3f..83d2539 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1792,11 +1792,14 @@ GetFontPath(ClientPtr client, int *count, int *length, unsigned char **result)
         fpe = font_path_elements[i];
         len += fpe->name_length + 1;
     }
-    font_path_string = (unsigned char *) realloc(font_path_string, len);
-    if (!font_path_string)
+    c = realloc(font_path_string, len);
+    if (c == NULL) {
+        free(font_path_string);
+        font_path_string = NULL;
         return BadAlloc;
+    }
 
-    c = font_path_string;
+    font_path_string = c;
     *length = 0;
     for (i = 0; i < num_fpes; i++) {
         fpe = font_path_elements[i];
-- 
1.7.9.2



More information about the xorg-devel mailing list