Fixed segmentation fault in TrueJet_Parser#57
Conversation
|
Can you find where the pointers are being used after being deleted and fix that? There may be some bigger issue on why that's happening instead of relying on checking for NULL. |
|
The edit is sufficient, because the objects to be deleted are only used by TrueJet_Parser::getall() or methods called by it. The rather trivial problem that is fixed by this PR comes from the fact that getall() may return before setting new objects. The delall() method intended to be called by the user at the end of each event for cleanup then attempts to call delete on the pointers again, resulting in undefined behavior (in my experience, segmentation faults). |
| if ( relfcn!= NULL ) { delete relfcn; relfcn = NULL; } | ||
| if ( relicn!= NULL ) { delete relicn; relicn = NULL; } | ||
| if ( relfp!= NULL ) { delete relfp; relfp = NULL; } | ||
| if ( relip!= NULL ) { delete relip; relip = NULL; } | ||
| if ( reltjreco != NULL) { delete reltjreco; reltjreco = NULL; } | ||
| if ( reltjmcp != NULL) { delete reltjmcp; reltjmcp = NULL; } | ||
| if ( jets != NULL) { delete jets; jets = NULL; } | ||
| if ( finalcns != NULL) { delete finalcns; finalcns = NULL; } | ||
| if ( initialcns!= NULL ) { delete initialcns; initialcns = NULL; } | ||
| if ( reltrue_tj != NULL ) { delete reltrue_tj; reltrue_tj = NULL; } |
There was a problem hiding this comment.
| if ( relfcn!= NULL ) { delete relfcn; relfcn = NULL; } | |
| if ( relicn!= NULL ) { delete relicn; relicn = NULL; } | |
| if ( relfp!= NULL ) { delete relfp; relfp = NULL; } | |
| if ( relip!= NULL ) { delete relip; relip = NULL; } | |
| if ( reltjreco != NULL) { delete reltjreco; reltjreco = NULL; } | |
| if ( reltjmcp != NULL) { delete reltjmcp; reltjmcp = NULL; } | |
| if ( jets != NULL) { delete jets; jets = NULL; } | |
| if ( finalcns != NULL) { delete finalcns; finalcns = NULL; } | |
| if ( initialcns!= NULL ) { delete initialcns; initialcns = NULL; } | |
| if ( reltrue_tj != NULL ) { delete reltrue_tj; reltrue_tj = NULL; } | |
| delete relfcn; relfcn = nullptr; | |
| delete relicn; relicn = nullptr; | |
| delete relfp; relfp = nullptr; | |
| delete relip; relip = nullptr; | |
| delete reltjreco; reltjreco = nullptr; | |
| delete reltjmcp; reltjmcp = nullptr; | |
| delete jets; jets = nullptr; | |
| delete finalcns; finalcns = nullptr; | |
| delete initialcns; initialcns = nullptr; | |
| delete reltrue_tj; reltrue_tj = nullptr; |
The important bit is setting to nullptr. Deleting a nullptr is defined and safe behavior per the c++ standard.
(Since we had this exact discussion yesterday in another context).
|
Then the proper fix is to turn all these into |
|
I think this is a classic "fortran c++" program, where the user side looks something like this, i think TrueJet_Parser parser;
for (int i = 0; i < nEvents; ++i) {
auto event = // from wherever;
parser.getall(event);
// do whatever you do
parser.delall();
}So turning these into |
|
But many of these are only used there inside the class. #58 should be exactly the same. |
BEGINRELEASENOTES
ENDRELEASENOTES