Skip to content

Commit

Permalink
Leak sanitizer: no false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDierheimer committed Sep 22, 2022
1 parent 991d02e commit 3d06530
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ else
fi
cmake --build . --target fastfetch ${cmake_build_extra_args}

export LSAN_OPTIONS=suppressions=../tests/lsan.supp
./fastfetch "$@"
9 changes: 7 additions & 2 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void initModuleArg(FFModuleArgs* args)

static void defaultConfig(FFinstance* instance)
{
ffStrbufInit(&instance->config.logo.source);
ffStrbufInitA(&instance->config.logo.source, 0);
instance->config.logo.type = FF_LOGO_TYPE_AUTO;
for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
ffStrbufInit(&instance->config.logo.colors[i]);
Expand Down Expand Up @@ -383,17 +383,22 @@ void ffFinish(FFinstance* instance)
ffLogoPrintRemaining(instance);

resetConsole();
}

void ffDestroyInstance(FFinstance* instance)
{
for(uint32_t i = 0; i < instance->state.configDirs.length; ++i)
ffStrbufDestroy((FFstrbuf*)ffListGet(&instance->state.configDirs, i));
ffListDestroy(&instance->state.configDirs);

ffStrbufDestroy(&instance->state.cacheDir);

for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i)
ffStrbufDestroy(&instance->config.logo.colors[i]);

ffStrbufDestroy(&instance->config.colorKeys);
ffStrbufDestroy(&instance->config.colorTitle);
ffStrbufDestroy(&instance->config.separator);
ffStrbufDestroy(&instance->config.logo.source);
}

//Must be in a file compiled with the libfastfetch target, because the FF_HAVE* macros are not defined for the executable targets
Expand Down
19 changes: 16 additions & 3 deletions src/common/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@

#include <stdarg.h>

//Clang doesn't define __SANITIZE_ADDRESS__ but defines __has_feature(address_sanitizer)
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define __SANITIZE_ADDRESS__
#endif
#endif

#ifdef __SANITIZE_ADDRESS__
#define FF_DLOPEN_FLAGS RTLD_LAZY | RTLD_NODELETE
#else
#define FF_DLOPEN_FLAGS RTLD_LAZY
#endif

static void* libraryLoad(const char* path, int maxVersion)
{
void* result = dlopen(path, RTLD_LAZY);
void* result = dlopen(path, FF_DLOPEN_FLAGS);
if(result != NULL || maxVersion < 0)
return result;

Expand All @@ -19,7 +32,7 @@ static void* libraryLoad(const char* path, int maxVersion)
uint32_t originalLength = pathbuf.length;
ffStrbufAppendF(&pathbuf, "%i", i);

result = dlopen(pathbuf.chars, RTLD_LAZY);
result = dlopen(pathbuf.chars, FF_DLOPEN_FLAGS);
if(result != NULL)
break;

Expand All @@ -33,7 +46,7 @@ static void* libraryLoad(const char* path, int maxVersion)
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...)
{
if(userProvidedName != NULL && userProvidedName->length > 0)
return dlopen(userProvidedName->chars, RTLD_LAZY);
return dlopen(userProvidedName->chars, FF_DLOPEN_FLAGS);

va_list defaultNames;
va_start(defaultNames, userProvidedName);
Expand Down
5 changes: 4 additions & 1 deletion src/fastfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,11 @@ int main(int argc, const char** argv)

startIndex = colonIndex + 1;
}

ffFinish(&instance);

ffStrbufDestroy(&data.structure);
ffValuestoreDestroy(&data.customValues);

ffFinish(&instance);
ffDestroyInstance(&instance);
}
1 change: 1 addition & 0 deletions src/fastfetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct FFinstance
void ffInitInstance(FFinstance* instance);
void ffStart(FFinstance* instance);
void ffFinish(FFinstance* instance);
void ffDestroyInstance(FFinstance* instance);

void ffListFeatures();

Expand Down
2 changes: 2 additions & 0 deletions src/modules/song.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ void ffPrintSong(FFinstance* instance)
ffStrbufAppendF(&songPretty, " (%s)", media->status.chars);

ffStrbufPutTo(&songPretty, stdout);

ffStrbufDestroy(&artistPretty);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions tests/lsan.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leak:*libwayland-client.so*

0 comments on commit 3d06530

Please sign in to comment.