Skip to content

Commit 60e002e

Browse files
committed
[webgui] improve TMethodCall usage
Use different signature when invoke method with arguments. If arguments provided as string - cling invoked leaving memory leak. Use different TMethodCall::Execute signature to avoid such leaks. (cherry picked from commit bc2ab1a)
1 parent 1a594a3 commit 60e002e

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

graf2d/gpadv7/src/TObjectDrawable.cxx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ using namespace ROOT::Experimental;
3535
void TObjectDrawable::CheckOwnership(TObject *obj)
3636
{
3737
if (obj && obj->InheritsFrom("TH1")) {
38-
TMethodCall call(obj->IsA(), "SetDirectory", "nullptr");
39-
call.Execute((void *)(obj));
38+
TMethodCall call;
39+
call.InitWithPrototype(obj->IsA(), "SetDirectory", "TDirectory*");
40+
if (call.IsValid()) {
41+
void *arg0 = nullptr;
42+
const void *method_args[1] = { &arg0 };
43+
call.Execute((void *) obj, method_args, 1);
44+
}
4045
} else if (obj && obj->InheritsFrom("TF1")) {
41-
TMethodCall call(obj->IsA(), "AddToGlobalList", "kFALSE");
42-
call.Execute((void *)(obj));
46+
TMethodCall call;
47+
call.InitWithPrototype(obj->IsA(), "AddToGlobalList", "Bool_t");
48+
if (call.IsValid()) {
49+
Bool_t arg0 = kFALSE;
50+
const void *method_args[1] = { &arg0 };
51+
call.Execute((void *) obj, method_args, 1);
52+
}
4353
}
4454
}
4555

gui/webgui6/src/TWebMenuItem.cxx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,12 @@ void TWebMenuItems::PopulateObjectMenu(void *obj, TClass *cl)
8383

8484
if ((getter.Length() > 0) && cl->GetMethodAllAny(getter)) {
8585
// execute getter method to get current state of toggle item
86-
87-
TMethodCall *call = new TMethodCall(cl, getter, "");
88-
89-
if (call->ReturnType() == TMethodCall::kLong) {
90-
Longptr_t l(0);
91-
call->Execute(obj, l);
92-
86+
TMethodCall call(cl, getter, "");
87+
if (call.ReturnType() == TMethodCall::kLong) {
88+
Longptr_t l = 0;
89+
call.Execute(obj, l);
9390
AddChkMenuItem(m->GetName(), m->GetTitle(), l != 0, TString::Format("%s(%s)", m->GetName(), (l != 0) ? "0" : "1").Data(), m->GetClass());
94-
95-
} else {
96-
// Error("CheckModifiedFlag", "Cannot get toggle value with getter %s", getter.Data());
9791
}
98-
99-
delete call;
10092
}
10193
} else {
10294
TList *args = m->GetListOfMethodArgs();

0 commit comments

Comments
 (0)