- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.8k
 
Closed
Labels
BugIt's a bugIt's a bugGood first issueIssues labeled as such are a good way to get use to the codebase. Ask for help if needed.Issues labeled as such are a good way to get use to the codebase. Ask for help if needed.HacktoberfestHigh Priorityhacktoberfest-accepted
Description
Description
Multiple memory leaks exist in the Region::process() function in src/utils/valuehandler.cpp. The function allocates memory for QApplication, char** array, and int* pointer but never cleans them up before returning.
Location
- File: 
src/utils/valuehandler.cpp - Function: 
Region::process()(lines 530-590) - Lines affected: 533-536, and all return statements
 
Current Code (Problematic)
// Memory allocated but never cleaned up
char** argv = new char*[1];           // Line 533 - never deleted
int* argc = new int{ 0 };            // Line 534 - never deleted
if (QGuiApplication::screens().empty()) {
    new QApplication(*argc, argv);   // Line 536 - never deleted
}
// ... function continues with multiple return statements
// None of the allocated memory is cleaned up before returningExpected Behavior
All allocated memory should be properly cleaned up before the function returns, regardless of which return path is taken.
Impact
- Multiple memory leaks on every call to 
Region::process() - QApplication objects accumulate in memory
 - char and int arrays** leak with each call
 - Potential application instability under heavy usage
 - Violates RAII principles
 
Proposed Fix
QVariant Region::process(const QVariant& val)
{
    char** argv = new char*[1];
    int* argc = new int{ 0 };
    QApplication* tempApp = nullptr;
    if (QGuiApplication::screens().empty()) {
        tempApp = new QApplication(*argc, argv);
    }
    
    // ... process logic ...
    
    // Cleanup before every return statement
    delete tempApp;
    delete[] argv;
    delete argc;
    return result;
}Steps to Reproduce
- Call 
Region::process()with any valid input - Monitor memory usage - memory will leak with each call
 - Repeat multiple times to see accumulation
 
Environment
- Any platform where Flameshot runs
 - Occurs on every call to 
Region::process() 
Priority
High - Multiple memory leaks that occur on every function call, can cause significant memory accumulation over time.
Additional Notes
- The function has a FIXME comment indicating this is temporary code before D-Bus removal
 - Even temporary code should not leak memory
 - This affects the configuration parsing system
 
Metadata
Metadata
Assignees
Labels
BugIt's a bugIt's a bugGood first issueIssues labeled as such are a good way to get use to the codebase. Ask for help if needed.Issues labeled as such are a good way to get use to the codebase. Ask for help if needed.HacktoberfestHigh Priorityhacktoberfest-accepted