Skip to content

Commit fa2f545

Browse files
committed
fix: 修复 optbox 失败内存泄露问题;
1 parent 92d5d80 commit fa2f545

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

screenshot.png

-53.2 KB
Loading

src/scriptaddon/scriptoptbox.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,13 @@ class OptBox {
437437
if (name.isEmpty()) {
438438
qWarning("[optbox::createWidget] Cannot create widget "
439439
"without a name.");
440+
delete w;
440441
return {};
441442
}
442443
if (_usedObjNames.contains(name) || usedNames.contains(name)) {
443444
qWarning("[optbox::createWidget] Cannot create widget with "
444445
"a used name.");
446+
delete w;
445447
return {};
446448
}
447449
usedNames.append(name);
@@ -451,6 +453,10 @@ class OptBox {
451453
_data.insert(cb, ControlType::Bool);
452454
layout->addWidget(cb);
453455
}
456+
if (usedNames.isEmpty()) {
457+
delete w;
458+
return {};
459+
}
454460
_usedObjNames.append(usedNames);
455461
ret.widget = w;
456462
} break;
@@ -477,17 +483,16 @@ class OptBox {
477483
if (name.isEmpty()) {
478484
qWarning("[optbox::createWidget] Cannot create widget "
479485
"without a name.");
486+
delete w;
480487
return {};
481488
}
482489
if (usedNames.contains(name)) {
483490
qWarning("[optbox::createWidget] Cannot create widget with "
484491
"a used name.");
492+
delete w;
485493
return {};
486494
}
487495
usedNames.append(name);
488-
if (dv.isEmpty()) {
489-
dv = name;
490-
}
491496
rb->setObjectName(name);
492497
rb->setToolTip(obj.value("tooltip").toString());
493498
QObject::connect(
@@ -502,6 +507,14 @@ class OptBox {
502507
layout->addWidget(rb);
503508
group.addButton(rb);
504509
}
510+
if (usedNames.isEmpty()) {
511+
delete w;
512+
return {};
513+
}
514+
if (dv.isEmpty() || !usedNames.contains(dv)) {
515+
dv = usedNames.first();
516+
group.button(-2)->setChecked(true);
517+
}
505518
w->setProperty(PROPERTY_DEFAULT, dv);
506519
ret.widget = w;
507520
_data.insert(w, type);

0 commit comments

Comments
 (0)