mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
Linux: fix some memleaks
This commit is contained in:
@@ -9,12 +9,14 @@ typedef struct X11PropertyData
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(XInternAtom)
|
||||
FF_LIBRARY_SYMBOL(XGetWindowProperty)
|
||||
FF_LIBRARY_SYMBOL(XFree)
|
||||
} X11PropertyData;
|
||||
|
||||
static bool x11InitPropertyData(void* libraryHandle, X11PropertyData* propertyData)
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XInternAtom, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XGetWindowProperty, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XFree, false)
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -29,7 +31,8 @@ static unsigned char* x11GetProperty(X11PropertyData* data, Display* display, Wi
|
||||
unsigned long unused;
|
||||
unsigned char* result = NULL;
|
||||
|
||||
data->ffXGetWindowProperty(display, window, requestAtom, 0, 64, False, AnyPropertyType, &actualType, (int*) &unused, &unused, &unused, &result);
|
||||
if(data->ffXGetWindowProperty(display, window, requestAtom, 0, 64, False, AnyPropertyType, &actualType, (int*) &unused, &unused, &unused, &result) != Success)
|
||||
return NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -43,14 +46,15 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl
|
||||
if(wmWindow == NULL)
|
||||
return;
|
||||
|
||||
const char* wmName = (const char*) x11GetProperty(data, display, *wmWindow, "_NET_WM_NAME");
|
||||
char* wmName = (char*) x11GetProperty(data, display, *wmWindow, "_NET_WM_NAME");
|
||||
if(wmName == NULL)
|
||||
wmName = (const char*) x11GetProperty(data, display, *wmWindow, "WM_NAME");
|
||||
wmName = (char*) x11GetProperty(data, display, *wmWindow, "WM_NAME");
|
||||
|
||||
if(!ffStrSet(wmName))
|
||||
return;
|
||||
if(ffStrSet(wmName))
|
||||
ffStrbufSetS(&result->wmProcessName, wmName);
|
||||
|
||||
ffStrbufSetS(&result->wmProcessName, wmName);
|
||||
data->ffXFree(wmName);
|
||||
data->ffXFree(wmWindow);
|
||||
}
|
||||
|
||||
void ffdsConnectXlib(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
|
||||
@@ -158,6 +158,7 @@ typedef struct GLXData
|
||||
FF_LIBRARY_SYMBOL(glXDestroyGLXPixmap)
|
||||
FF_LIBRARY_SYMBOL(XFreePixmap)
|
||||
FF_LIBRARY_SYMBOL(XCloseDisplay)
|
||||
FF_LIBRARY_SYMBOL(XFree)
|
||||
|
||||
Display* display;
|
||||
XVisualInfo* visualInfo;
|
||||
@@ -213,7 +214,9 @@ static const char* glxHandleDisplay(FFOpenGLResult* result, GLXData* data)
|
||||
if(data->visualInfo == NULL)
|
||||
return "glXChooseVisual returned NULL";
|
||||
|
||||
return glxHandleVisualInfo(result, data);
|
||||
const char* error = glxHandleVisualInfo(result, data);
|
||||
data->ffXFree(data->visualInfo);
|
||||
return error;
|
||||
}
|
||||
|
||||
static const char* glxHandleData(FFOpenGLResult* result, GLXData* data)
|
||||
@@ -247,6 +250,7 @@ static const char* glxPrint(FFinstance* instance, FFOpenGLResult* result)
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXDestroyGLXPixmap);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XFreePixmap);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XCloseDisplay);
|
||||
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XFree);
|
||||
|
||||
const char* error = glxHandleData(result, &data);
|
||||
dlclose(glx);
|
||||
|
||||
Reference in New Issue
Block a user