0

When I try to load a font in Xlib via XLoadQueryFont with the following font name "fixed", the program does not leak, and everything is freed in the end.

When I try to load another font, the programs still works fine, however valgrind points a memory leak.

What could cause this problem? Notice that the program works fine with both fonts, and it loads them correctly. I have the font installed. It also leaks with these:

"-adobe-*-*-*-*-*-14-*-*-*-*-*-*-*"
"-*-*-*-*-*-*-14-*-*-*-*-*-*-*"
"-misc-*-*-*-*-*-*-*-*-*-*-*-*-*"

and many varitions. They load, but leaks memory.

This is a minimal example

#include <X11/Xlib.h>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

void
main()
{
  Display* display;
  XFontStruct* font_info;       /* Font structure, used for drawing text.    */
  char* font_name = "*-helvetica-*-12-*"; /* font to use for drawing text.   */
//  char *font_name = "fixed";

  /* open connection with the X server. */
  display = XOpenDisplay(getenv("DISPLAY"));
  if (display == NULL) {
    fprintf(stderr, "cannot connect to X server\n");
    exit(1);
  }

  /* try to load the given font. */
  font_info = XLoadQueryFont(display, font_name);
  if (!font_info) {
      fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name);
      exit(-1);
  }

  /* close the connection to the X server. */
  XFreeFont(display, font_info);
  XCloseDisplay(display);
}

This is the valgrind log for when the leak happens: https://pastebin.com/gg3AhZeh

Using pastebin since it exceeded the limit.

I expect the program to end correctly freeing all bytes previousy allocated.

Socrates
  • 33
  • 3

0 Answers0