libi3: free previous font on font load

When loading a new font with `load_font`, free the previously loaded
font with `free_font`.

If no font is loaded, `free_font` will simply return (instead of
crashing because of a double free).
This commit is contained in:
Tony Crisci
2015-02-10 15:11:40 -05:00
parent d38d2dc3e3
commit e91a9174e2
2 changed files with 17 additions and 4 deletions

View File

@ -290,7 +290,8 @@ uint32_t get_mod_mask_for(uint32_t keysym,
/**
* Loads a font for usage, also getting its height. If fallback is true,
* the fonts 'fixed' or '-misc-*' will be loaded instead of exiting.
* the fonts 'fixed' or '-misc-*' will be loaded instead of exiting. If any
* font was previously loaded, it will be freed.
*
*/
i3Font load_font(const char *pattern, const bool fallback);
@ -302,7 +303,8 @@ i3Font load_font(const char *pattern, const bool fallback);
void set_font(i3Font *font);
/**
* Frees the resources taken by the current font.
* Frees the resources taken by the current font. If no font was previously
* loaded, it simply returns.
*
*/
void free_font(void);