Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRestMetadata: undefine = operator method overload #116

Merged
merged 2 commits into from
Jan 4, 2022
Merged

Conversation

nkx111
Copy link
Member

@nkx111 nkx111 commented Dec 9, 2021

nkx111 4

It will cause double free problems if we use = or copy constructor for metadata classes. The reason is that the data member fElement as a pointer will also be copied. And when we delete the two metadata classes, the same pointer will be deleted twice. For example:

TRestDetectorGas *g=new TRestDetectorGas("server","Xenon-TMA 0.1Pct 10-10E3Vcm") // initialize a metadata
{TRestDetectorGas gg = *g;} // make a new copy and delete.
delete g;  // this delete operation will cause seg.fault

In this PR I undefined the = operator. Now the second line doesn't work, and avoids this problem.

Now to copy metadata or to use the object(instead of pointer), one can use Clone(), or reference:

TRestDetectorGas* g=new TRestDetectorGas("server","Xenon-TMA 0.1Pct 10-10E3Vcm") 
TRestDetectorGas* gg = (TRestDetectorGas*)g->Clone();
delete g; 
delete gg;
TRestDetectorGas *g=new TRestDetectorGas("server","Xenon-TMA 0.1Pct 10-10E3Vcm")
{TRestDetectorGas& gg = *g;}
delete g;

@nkx111 nkx111 requested review from jgalan, juanangp and lobis December 9, 2021 07:47
@jgalan jgalan requested a review from lobis December 9, 2021 10:24
@jgalan
Copy link
Member

jgalan commented Dec 9, 2021

Hi @lobis, it is great you took your time to review and approve this PR. However, we should wait till the pipeline is green. So I just requested a second review.

@jgalan
Copy link
Member

jgalan commented Dec 9, 2021

I have created a new PR at detector library to try to fix the pipeline rest-for-physics/detectorlib#29

@jgalan jgalan merged commit 539252a into master Jan 4, 2022
@jgalan jgalan deleted the nkx111-patch-2 branch January 4, 2022 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants