Repository: fastfetch-cli/fastfetch
File: src/common/logo.c (C)

Code before:

static void loadLogoFromFile(FFlogo* logo, bool doColor, FFstrbuf* configColor, const char* pathToFile)
{
    const char* color = doColor ? configColor->chars : "";
    strcpy(logo->color, color);

    FILE* fp = fopen(pathToFile, "r");
    char* buff = NULL;
    size_t buffLen = 0;
    int lineBytes;
    int lineLength;

    int logoWidth = 0, logoHeight = 0;
    while( (lineBytes=getline(&buff, &buffLen, fp)) != -1 ) {
        // Remove trailing newline
        if(buff[lineBytes-1] == '\n')
            buff[lineBytes-1] = '\0';
        
        sprintf(logo->chars[logoHeight++],   FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET, color, buff);

        lineLength = utf8_strlen(buff);
        logoWidth = lineLength > logoWidth
            ? lineLength
            : logoWidth;
    }

    fclose(fp);

    logo->width = logoWidth;
    logo->height = logoHeight;
}

void ffLoadLogoSet(FFconfig* config, const char* logo)
{
    if(config->readLogoFromFile) {
        ffLoadLogoFromFile(config, logo);
    } else {
        if(strcasecmp(logo, "none") == 0)
        {
            loadNoneLogo(&config->logo);
            config->logo_spacing = 0; //This is wanted in most cases, so just set it
        }
        else if(strcasecmp(logo, "arch") == 0)
            loadArchLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "artix") == 0)
            loadArtixLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "ubuntu") == 0)
            loadUbuntuLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "debian") == 0)
            loadDebianLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "manjaro") == 0)

Review comment (suggestion):
insert a 
```c
if(buff != NULL)
    free(buff);
```
here

Code after:

static void loadLogoFromFile(FFlogo* logo, bool doColor, FFstrbuf* configColor, const char* pathToFile)
{
    const char* color = doColor ? configColor->chars : "";
    strcpy(logo->color, color);

    FILE* fp = fopen(pathToFile, "r");
    char* buff = NULL;
    size_t buffLen = 0;
    int lineBytes;
    int lineLength;

    int logoWidth = 0, logoHeight = 0;
    while( (lineBytes=getline(&buff, &buffLen, fp)) != -1 ) {
        // Remove trailing newline
        if(buff[lineBytes-1] == '\n')
            buff[lineBytes-1] = '\0';
        
        sprintf(logo->chars[logoHeight++],   FASTFETCH_TEXT_MODIFIER_BOLT"%s%s"FASTFETCH_TEXT_MODIFIER_RESET, color, buff);

        lineLength = utf8_strlen(buff);
        logoWidth = lineLength > logoWidth
            ? lineLength
            : logoWidth;
    }

    // Clean up
    fclose(fp);
    if(buff != NULL)
        free(buff);

    logo->width = logoWidth;
    logo->height = logoHeight;
}

void ffLoadLogoSet(FFconfig* config, const char* logo)
{
    if(config->readLogoFromFile) {
        ffLoadLogoFromFile(config, logo);
    } else {
        if(strcasecmp(logo, "none") == 0)
        {
            loadNoneLogo(&config->logo);
            config->logo_spacing = 0; //This is wanted in most cases, so just set it
        }
        else if(strcasecmp(logo, "arch") == 0)
            loadArchLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "artix") == 0)
            loadArtixLogo(&config->logo, config->colorLogo);
        else if(strcasecmp(logo, "ubuntu") == 0)
            loadUbuntuLogo(&config->logo, config->colorLogo);