Repository: fastfetch-cli/fastfetch
File: src/modules/terminalfont.c (C)

Code before:
    FFstrbuf fontName;
    FFstrbuf fontSize;
    ffStrbufInit(&fontName);
    ffStrbufInit(&fontSize);

    FFpropquery fontQuery[] = {
        {"family:", &fontName},
        {"size:", &fontSize},
    };

    // alacritty parses config files in this order
    ffParsePropFileConfigValues(instance, "alacritty/alacritty.yml", 2, fontQuery);
    if(fontName.length == 0 || fontSize.length == 0)
        ffParsePropFileConfigValues(instance, "alacritty.yml", 2, fontQuery);
    if(fontName.length == 0 || fontSize.length == 0)
        ffParsePropFileConfigValues(instance, ".alacritty.yml", 2, fontQuery);
    if(fontName.length == 0 || fontSize.length == 0)
    {
         //by default alacritty uses it's own font called alacritty at size 11
        ffStrbufAppendS(&fontName, "alacritty");
        ffStrbufAppendS(&fontSize, "11");
    }

    FFfont font;
    ffFontInitCopy(&font, fontName.chars);
    ffStrbufInitCopy(&font.size, &fontSize);
    printTerminalFont(instance, fontName.chars, &font);
    ffFontDestroy(&font);

    ffStrbufDestroy(&fontName);
    ffStrbufDestroy(&fontSize);
}

static void printTTY(FFinstance* instance)
{
    FFstrbuf fontName;
    ffStrbufInit(&fontName);

    ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/vconsole.conf", "Font =", &fontName);

    if(fontName.length == 0)
    {
        ffStrbufAppendS(&fontName, "VGA default kernel font ");
        ffProcessAppendStdOut(&fontName, (char* const[]){
            "showconsolefont",
            "--info",
            NULL
        });
    }

    ffStrbufTrimRight(&fontName, ' ');

Review comment (suggestion):
`font.size` is already initialized by fontInitCopy. A simple `ffStrbufAppend` should do the trick. Otherwise we leak memory.

Code after:
    FFstrbuf fontName;
    FFstrbuf fontSize;
    ffStrbufInit(&fontName);
    ffStrbufInit(&fontSize);

    FFpropquery fontQuery[] = {
        {"family:", &fontName},
        {"size:", &fontSize},
    };

    // alacritty parses config files in this order
    ffParsePropFileConfigValues(instance, "alacritty/alacritty.yml", 2, fontQuery);
    if(fontName.length == 0 || fontSize.length == 0)
        ffParsePropFileConfigValues(instance, "alacritty.yml", 2, fontQuery);
    if(fontName.length == 0 || fontSize.length == 0)
        ffParsePropFileConfigValues(instance, ".alacritty.yml", 2, fontQuery);

    //by default alacritty uses it's own font called alacritty
    if(fontName.length == 0)
        ffStrbufAppendS(&fontName, "alacritty");

    // the default font size is 11
    if(fontSize.length == 0)
        ffStrbufAppendS(&fontSize, "11");

    FFfont font;
    ffFontInitCopy(&font, fontName.chars);
    ffStrbufAppend(&font.size, &fontSize);
    printTerminalFont(instance, fontName.chars, &font);
    ffFontDestroy(&font);

    ffStrbufDestroy(&fontName);
    ffStrbufDestroy(&fontSize);
}

static void printTTY(FFinstance* instance)
{
    FFstrbuf fontName;
    ffStrbufInit(&fontName);

    ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/vconsole.conf", "Font =", &fontName);

    if(fontName.length == 0)
    {
        ffStrbufAppendS(&fontName, "VGA default kernel font ");
        ffProcessAppendStdOut(&fontName, (char* const[]){
            "showconsolefont",
            "--info",
            NULL
        });
    }