LordGrey 05d24b99c4
Fix Memory leaks (#1678)
* Refactor to fix #1671

* Add GUI/NonGUI mode to info page

* Do not show lock config, if in non-UI mode

* Updae Changelog

* Correct includes

* Ensure key member initialization - RGB Channels

* Ensure key member initialization - WebServer

* Update RGBChannels

* Fix initialization order

* Fix key when inserting new logger in LoggerMap,
Prepare logBuffer-JSON snapshot view in LoggerManager,
Increase buffered loglines to 500

* Fix Memory leak in GrabberWrapper

* Fix Memory leak in BlackBorderProcessor

* Fix Memory leak in BlackBorderProcessor

* use ninja generator under macos

* Fix BGEffectHandler destruction

* Fix Mdns code

* Clear list after applying qDeleteAll

* Fix deletion of CecHandler

* Fix memory leak caused by wrong buffer allocation

* Remove extra pixel consistently

* Change mDNS to Qt SmartPointers

* Correct removal

* Fix usage of _width/_height (they are the output resolution, not the screen resolution)
That avoids unnecessary resizing of the output image with every transferFrame call

* Move main non Thread Objects to Smart Pointers

* Revert "Move main non Thread Objects to Smart Pointers"

This reverts commit 26102ca963982e2fbc4ffb8d4db6139f0128a3cc.

* Add missing deletes

* Revert MdnsBrowser chnage

* Revert MdnsBrowser change

* Fix memory leaks related standalone grabber

* Address CodeQL finding

* delete pointer OsxFrameGrabber

---------

Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
2024-01-13 17:04:45 +01:00

100 lines
2.0 KiB
C++

#include "commandline/Parser.h"
using namespace commandline;
Parser::~Parser()
{
qDeleteAll(_options);
_options.clear();
}
bool Parser::parse(const QStringList &arguments)
{
if (!_parser.parse(arguments))
{
return false;
}
for(Option * option : std::as_const(_options))
{
if (!option->valueName().isEmpty())
{
QString value = this->value(*option);
if (!option->validate(*this, value)) {
const QString error = option->getError();
if (!error.isEmpty()) {
_errorText = tr("\"%1\" is not a valid option for %2, %3").arg(value, option->name(), error);
}
else
{
_errorText = tr("\"%1\" is not a valid option for %2").arg(value, option->name());
}
return false;
}
}
}
return true;
}
void Parser::process(const QStringList &arguments)
{
_parser.process(arguments);
if (!parse(arguments))
{
fprintf(stdout, "%s\n\n", qPrintable(tr("Error: %1").arg(_errorText)));
showHelp(EXIT_FAILURE);
}
}
void Parser::process(const QCoreApplication& /*app*/)
{
process(QCoreApplication::arguments());
}
QString Parser::errorText() const
{
return (!_errorText.isEmpty()) ? _errorText : _parser.errorText();
}
bool Parser::addOption(Option &option)
{
return addOption(&option);
}
bool Parser::addOption(Option * const option)
{
_options[option->name()] = option;
return _parser.addOption(*option);
}
QStringList Parser::_getNames(const char shortOption, const QString& longOption)
{
QStringList names;
if (shortOption != 0x0)
{
names << QString(shortOption);
}
if (longOption.size() != 0)
{
names << longOption;
}
return names;
}
QString Parser::_getDescription(const QString& description, const QString& default_)
{
/* Add the translations if available */
QString formattedDescription(tr(qPrintable(description)));
/* Fill in the default if needed */
if (!default_.isEmpty())
{
if(!formattedDescription.contains("%1"))
{
formattedDescription += " [default: %1]";
}
formattedDescription = formattedDescription.arg(default_);
}
return formattedDescription;
}