]> git.sur5r.net Git - i3/i3/blobdiff - libi3/font.c
Fix memory leak
[i3/i3] / libi3 / font.c
index 7d776ad1350054ac1495e9747e9a9158dccc8cf0..32744c0b7291d1ffe8e2724dc2caa56668906789 100644 (file)
@@ -163,6 +163,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
 
     i3Font font;
     font.type = FONT_TYPE_NONE;
+    font.pattern = NULL;
 
     /* No XCB connction, return early because we're just validating the
      * configuration file. */
@@ -223,9 +224,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
                      error->error_code);
         }
     }
-    if (error != NULL) {
-        free(error);
-    }
+    free(error);
 
     font.pattern = sstrdup(pattern);
     LOG("Using X font %s\n", pattern);
@@ -274,8 +273,7 @@ void free_font(void) {
         case FONT_TYPE_XCB: {
             /* Close the font and free the info */
             xcb_close_font(conn, savedFont->specific.xcb.id);
-            if (savedFont->specific.xcb.info)
-                free(savedFont->specific.xcb.info);
+            free(savedFont->specific.xcb.info);
             break;
         }
         case FONT_TYPE_PANGO:
@@ -438,6 +436,7 @@ static int xcb_query_text_width(const xcb_char2b_t *text, size_t text_len) {
          * a crash. Plus, the user will see the error in their log. */
         fprintf(stderr, "Could not get text extents (X error code %d)\n",
                 error->error_code);
+        free(error);
         return savedFont->specific.xcb.info->max_bounds.character_width * text_len;
     }