mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
fix: fixed several other memory leaks
This commit is contained in:
parent
8938d505ca
commit
e463ccc22f
@ -1 +1 @@
|
|||||||
3801
|
3803
|
||||||
|
@ -18,6 +18,12 @@ namespace Qv2ray::common
|
|||||||
return randomString;
|
return randomString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString StringFromFile(const QString &filePath)
|
||||||
|
{
|
||||||
|
QFile f(filePath);
|
||||||
|
return StringFromFile(&f);
|
||||||
|
}
|
||||||
|
|
||||||
QString StringFromFile(QFile *source)
|
QString StringFromFile(QFile *source)
|
||||||
{
|
{
|
||||||
source->open(QFile::ReadOnly);
|
source->open(QFile::ReadOnly);
|
||||||
|
@ -19,6 +19,7 @@ namespace Qv2ray::common
|
|||||||
void QvMessageBoxInfo(QWidget *parent, QString title, QString text);
|
void QvMessageBoxInfo(QWidget *parent, QString title, QString text);
|
||||||
QMessageBox::StandardButton QvMessageBoxAsk(QWidget *parent, QString title, QString text, QMessageBox::StandardButton extraButtons = QMessageBox::NoButton);
|
QMessageBox::StandardButton QvMessageBoxAsk(QWidget *parent, QString title, QString text, QMessageBox::StandardButton extraButtons = QMessageBox::NoButton);
|
||||||
//
|
//
|
||||||
|
QString StringFromFile(const QString &filePath);
|
||||||
QString StringFromFile(QFile *source);
|
QString StringFromFile(QFile *source);
|
||||||
bool StringToFile(const QString *text, QFile *target);
|
bool StringToFile(const QString *text, QFile *target);
|
||||||
//
|
//
|
||||||
|
@ -38,7 +38,7 @@ namespace Qv2ray::components::pac
|
|||||||
//
|
//
|
||||||
DEBUG(PROXY, "PAC Listening local endpoint: " + address + ":" + QSTRN(port))
|
DEBUG(PROXY, "PAC Listening local endpoint: " + address + ":" + QSTRN(port))
|
||||||
//
|
//
|
||||||
QString gfwContent = StringFromFile(std::make_unique<QFile>(QV2RAY_RULES_GFWLIST_PATH).get());
|
QString gfwContent = StringFromFile(QV2RAY_RULES_GFWLIST_PATH);
|
||||||
pacContent = ConvertGFWToPAC(gfwContent, proxyString);
|
pacContent = ConvertGFWToPAC(gfwContent, proxyString);
|
||||||
//
|
//
|
||||||
auto result = pacServer->listen(QHostAddress(address), static_cast<ushort>(port));
|
auto result = pacServer->listen(QHostAddress(address), static_cast<ushort>(port));
|
||||||
|
@ -60,6 +60,7 @@ namespace Qv2ray::components::plugins::Toolbar
|
|||||||
}
|
}
|
||||||
|
|
||||||
server->close();
|
server->close();
|
||||||
|
delete server;
|
||||||
}
|
}
|
||||||
void StartMessageQThread()
|
void StartMessageQThread()
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ namespace Qv2ray::core::connection
|
|||||||
{
|
{
|
||||||
CONFIGROOT _ReadConnection(const QString &connection)
|
CONFIGROOT _ReadConnection(const QString &connection)
|
||||||
{
|
{
|
||||||
QString jsonString = StringFromFile(std::make_unique<QFile>(connection).get());
|
QString jsonString = StringFromFile(connection);
|
||||||
auto conf = CONFIGROOT(JsonFromString(jsonString));
|
auto conf = CONFIGROOT(JsonFromString(jsonString));
|
||||||
|
|
||||||
if (conf.count() == 0) {
|
if (conf.count() == 0) {
|
||||||
@ -71,17 +71,18 @@ namespace Qv2ray::core::connection
|
|||||||
bool SaveConnectionConfig(CONFIGROOT obj, QString *alias, bool canOverrideExisting)
|
bool SaveConnectionConfig(CONFIGROOT obj, QString *alias, bool canOverrideExisting)
|
||||||
{
|
{
|
||||||
auto str = JsonToString(obj);
|
auto str = JsonToString(obj);
|
||||||
QFile *config = new QFile(QV2RAY_CONFIG_DIR + *alias + QV2RAY_CONFIG_FILE_EXTENSION);
|
auto fullPath = QV2RAY_CONFIG_DIR + *alias + QV2RAY_CONFIG_FILE_EXTENSION;
|
||||||
|
|
||||||
// If there's already a file AND we CANNOT override existing file.
|
// If there's already a file AND we CANNOT override existing file.
|
||||||
if (config->exists() && !canOverrideExisting) {
|
if (QFile::exists(fullPath) && !canOverrideExisting) {
|
||||||
// Alias is a pointer to a QString.
|
// Alias is a pointer to a QString.
|
||||||
DeducePossibleFileName(QV2RAY_CONFIG_DIR, alias, QV2RAY_CONFIG_FILE_EXTENSION);
|
DeducePossibleFileName(QV2RAY_CONFIG_DIR, alias, QV2RAY_CONFIG_FILE_EXTENSION);
|
||||||
config = new QFile(QV2RAY_CONFIG_DIR + *alias + QV2RAY_CONFIG_FILE_EXTENSION);
|
fullPath = QV2RAY_CONFIG_DIR + *alias + QV2RAY_CONFIG_FILE_EXTENSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(SETTINGS, "Saving a config named: " + *alias)
|
LOG(SETTINGS, "Saving a config named: " + *alias)
|
||||||
return StringToFile(&str, config);
|
QFile config(fullPath);
|
||||||
|
return StringToFile(&str, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SaveSubscriptionConfig(CONFIGROOT obj, const QString &subscription, QString *name)
|
bool SaveSubscriptionConfig(CONFIGROOT obj, const QString &subscription, QString *name)
|
||||||
@ -93,15 +94,15 @@ namespace Qv2ray::core::connection
|
|||||||
fName = RemoveInvalidFileName(fName);
|
fName = RemoveInvalidFileName(fName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFile *config = new QFile(QV2RAY_SUBSCRIPTION_DIR + subscription + "/" + fName + QV2RAY_CONFIG_FILE_EXTENSION);
|
QFile config(QV2RAY_SUBSCRIPTION_DIR + subscription + "/" + fName + QV2RAY_CONFIG_FILE_EXTENSION);
|
||||||
|
|
||||||
// If there's already a file. THIS IS EXTREMELY RARE
|
// If there's already a file. THIS IS EXTREMELY RARE
|
||||||
if (config->exists()) {
|
if (config.exists()) {
|
||||||
LOG(FILEIO, "Trying to overrwrite an existing subscription config file. THIS IS RARE")
|
LOG(FILEIO, "Trying to overrwrite an existing subscription config file. THIS IS RARE")
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(SETTINGS, "Saving a subscription named: " + fName)
|
LOG(SETTINGS, "Saving a subscription named: " + fName)
|
||||||
bool result = StringToFile(&str, config);
|
bool result = StringToFile(&str, &config);
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
LOG(FILEIO, "Failed to save a connection config from subscription: " + subscription + ", name: " + fName)
|
LOG(FILEIO, "Failed to save a connection config from subscription: " + subscription + ", name: " + fName)
|
||||||
|
@ -52,7 +52,7 @@ namespace Qv2ray::core::kernel::api
|
|||||||
thread->wait();
|
thread->wait();
|
||||||
|
|
||||||
// Although thread shouldnot be null, we'll add this check to be safe.
|
// Although thread shouldnot be null, we'll add this check to be safe.
|
||||||
if (thread != nullptr) {
|
if (thread) {
|
||||||
delete thread;
|
delete thread;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,8 +145,10 @@ namespace Qv2ray::core::kernel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the final configuration to the disk.
|
// Write the final configuration to the disk.
|
||||||
|
|
||||||
QString json = JsonToString(root);
|
QString json = JsonToString(root);
|
||||||
StringToFile(&json, new QFile(QV2RAY_GENERATED_FILE_PATH));
|
QFile configFile(QV2RAY_GENERATED_FILE_PATH);
|
||||||
|
StringToFile(&json, &configFile);
|
||||||
//
|
//
|
||||||
auto filePath = QV2RAY_GENERATED_FILE_PATH;
|
auto filePath = QV2RAY_GENERATED_FILE_PATH;
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the config for upgrade, but do not parse it to the struct.
|
// Load the config for upgrade, but do not parse it to the struct.
|
||||||
auto conf = JsonFromString(StringFromFile(std::make_unique<QFile>(QV2RAY_CONFIG_FILE).get()));
|
auto conf = JsonFromString(StringFromFile(QV2RAY_CONFIG_FILE));
|
||||||
auto confVersion = conf["config_version"].toVariant().toString().toInt();
|
auto confVersion = conf["config_version"].toVariant().toString().toInt();
|
||||||
|
|
||||||
if (confVersion > QV2RAY_CONFIG_VERSION) {
|
if (confVersion > QV2RAY_CONFIG_VERSION) {
|
||||||
|
@ -8,6 +8,12 @@ class QvInboundNodeModel : public NodeDataModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QvInboundNodeModel(std::shared_ptr<InboundNodeData> data);
|
explicit QvInboundNodeModel(std::shared_ptr<InboundNodeData> data);
|
||||||
|
~QvInboundNodeModel()
|
||||||
|
{
|
||||||
|
if (_label) {
|
||||||
|
delete _label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString caption() const override
|
QString caption() const override
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,12 @@ class QvOutboundNodeModel : public NodeDataModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QvOutboundNodeModel(std::shared_ptr<OutboundNodeData> data);
|
explicit QvOutboundNodeModel(std::shared_ptr<OutboundNodeData> data);
|
||||||
|
~QvOutboundNodeModel()
|
||||||
|
{
|
||||||
|
if (_label) {
|
||||||
|
delete _label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString caption() const override
|
QString caption() const override
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,12 @@ class QvRuleNodeDataModel : public NodeDataModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QvRuleNodeDataModel(std::shared_ptr<RuleNodeData> data);
|
QvRuleNodeDataModel(std::shared_ptr<RuleNodeData> data);
|
||||||
|
~QvRuleNodeDataModel()
|
||||||
|
{
|
||||||
|
if (_label) {
|
||||||
|
delete _label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString caption() const override
|
QString caption() const override
|
||||||
{
|
{
|
||||||
|
@ -67,11 +67,10 @@ void ImportConfigWindow::on_qrFromScreenBtn_clicked()
|
|||||||
|
|
||||||
QApplication::processEvents();
|
QApplication::processEvents();
|
||||||
QThread::msleep(static_cast<ulong>(doubleSpinBox->value() * 1000));
|
QThread::msleep(static_cast<ulong>(doubleSpinBox->value() * 1000));
|
||||||
auto w = new ScreenShotWindow();
|
ScreenShotWindow w;
|
||||||
auto pix = w->DoScreenShot();
|
auto pix = w.DoScreenShot();
|
||||||
auto _r = w->result();
|
auto _r = w.result();
|
||||||
// Explicitly delete w to call UNREGISTER_WINDOW
|
// Explicitly delete w to call UNREGISTER_WINDOW
|
||||||
delete w;
|
|
||||||
|
|
||||||
if (hideQv2ray) {
|
if (hideQv2ray) {
|
||||||
messageBus.EmitGlobalSignal(QvMessage::SHOW_WINDOWS);
|
messageBus.EmitGlobalSignal(QvMessage::SHOW_WINDOWS);
|
||||||
|
@ -889,9 +889,9 @@ void MainWindow::on_action_RCM_ConvToComplex_triggered()
|
|||||||
bool isChanged = false;
|
bool isChanged = false;
|
||||||
//
|
//
|
||||||
LOG(UI, "INFO: Opening route editor.")
|
LOG(UI, "INFO: Opening route editor.")
|
||||||
RouteEditor *routeWindow = new RouteEditor(outBoundRoot, this);
|
RouteEditor routeWindow(outBoundRoot, this);
|
||||||
root = routeWindow->OpenEditor();
|
root = routeWindow.OpenEditor();
|
||||||
isChanged = routeWindow->result() == QDialog::Accepted;
|
isChanged = routeWindow.result() == QDialog::Accepted;
|
||||||
QString alias = _identifier.connectionName;
|
QString alias = _identifier.connectionName;
|
||||||
|
|
||||||
if (isChanged) {
|
if (isChanged) {
|
||||||
|
@ -22,7 +22,7 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent),
|
|||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
QvMessageBusConnect(PreferencesWindow);
|
QvMessageBusConnect(PreferencesWindow);
|
||||||
textBrowser->setHtml(StringFromFile(new QFile(":/assets/credit.html")));
|
textBrowser->setHtml(StringFromFile(":/assets/credit.html"));
|
||||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
//
|
//
|
||||||
// Set network Toolbar page state.
|
// Set network Toolbar page state.
|
||||||
@ -820,46 +820,46 @@ void PreferencesWindow::on_pacGoBtn_clicked()
|
|||||||
QString fileContent;
|
QString fileContent;
|
||||||
pacGoBtn->setEnabled(false);
|
pacGoBtn->setEnabled(false);
|
||||||
gfwListCB->setEnabled(false);
|
gfwListCB->setEnabled(false);
|
||||||
auto request = new QvHttpRequestHelper();
|
QvHttpRequestHelper request;
|
||||||
LOG(PROXY, "Downloading GFWList file.")
|
LOG(PROXY, "Downloading GFWList file.")
|
||||||
bool withProxy = getGFWListWithProxyCB->isChecked();
|
bool withProxy = getGFWListWithProxyCB->isChecked();
|
||||||
|
|
||||||
switch (gfwListCB->currentIndex()) {
|
switch (gfwListCB->currentIndex()) {
|
||||||
case 0:
|
case 0:
|
||||||
gfwLocation = "https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt";
|
gfwLocation = "https://gitlab.com/gfwlist/gfwlist/raw/master/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
gfwLocation = "https://pagure.io/gfwlist/raw/master/f/gfwlist.txt";
|
gfwLocation = "https://pagure.io/gfwlist/raw/master/f/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
gfwLocation = "http://repo.or.cz/gfwlist.git/blob_plain/HEAD:/gfwlist.txt";
|
gfwLocation = "http://repo.or.cz/gfwlist.git/blob_plain/HEAD:/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
gfwLocation = "https://bitbucket.org/gfwlist/gfwlist/raw/HEAD/gfwlist.txt";
|
gfwLocation = "https://bitbucket.org/gfwlist/gfwlist/raw/HEAD/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
gfwLocation = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt";
|
gfwLocation = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
gfwLocation = "https://git.tuxfamily.org/gfwlist/gfwlist.git/plain/gfwlist.txt";
|
gfwLocation = "https://git.tuxfamily.org/gfwlist/gfwlist.git/plain/gfwlist.txt";
|
||||||
fileContent = QString::fromUtf8(request->syncget(gfwLocation, withProxy));
|
fileContent = QString::fromUtf8(request.syncget(gfwLocation, withProxy));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
QFileDialog d;
|
QFileDialog d;
|
||||||
d.exec();
|
d.exec();
|
||||||
auto file = d.getOpenFileUrl(this, tr("Select GFWList in base64")).toString();
|
auto file = d.getOpenFileUrl(this, tr("Select GFWList in base64")).toString();
|
||||||
fileContent = StringFromFile(new QFile(file));
|
fileContent = StringFromFile(file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user