-
Notifications
You must be signed in to change notification settings - Fork 17
Refactor error handling for memory allocation failure #23
Copy link
Copy link
Open
Description
Describe the refactoring action
The codebase uses C++'s new but handles allocation failures as if it were C's malloc by checking if the returned pointer is NULL, while new in C++ throws a std::bad_alloc if it fails, unless the call is marked with std::no_throw.
Possible actions
- Do nothing: If we leave the NULL checking code as is then it just stays as dead code. This is not a particularly high-severity issue IMO
- Add
std::no_throwto the calls tonew. This will keep the current error handling code as new will return NULL on failure. - Remove the error handling code: Allocation failure means something else has gone terribly wrong and there is little that can be done to handle a bad_alloc [1] [2], so might as well let it go uncaught and terminate the program. We can replace some of the calls to new with smart pointers where the API permits.
An overview of misuses:
Collected by a Python script, may not be complete
./src/jni/jni.cpp:
[line:356] pInstance
./src/utils/deployCppService.hpp:
[line:848] singleton_pLogger
./src/utils/runAECpp.cpp:
[line:382] pBuffer
./src/utils/ActiveMQAnalysisEngineService.cpp:
[line:620] connection
[line:638] connection
[line:1290] newConnection
[line:1353] newListener
[line:1378] iv_pgetMetaConnection
[line:1396] newListener
./src/framework/engine.cpp:
[line:215] pResult
./src/framework/taespecifierbuilder.cpp:
[line:186] iv_pXMLErrorHandler
[line:232] iv_pXMLErrorHandler
[line:271] iv_pXMLErrorHandler
[line:313] iv_pXMLErrorHandler
[line:1898] iv_pXMLErrorHandler
[line:1980] iv_pXMLErrorHandler
./src/framework/annotator_context.cpp:
[line:169] iv_pCasPool
./src/framework/internal_primitive_engine.cpp:
[line:102] iv_pAnnotator
./src/framework/resmgr.cpp:
[line:581] pDllFile
[line:670] cv_pclSingletonInstance->iv_fileLogger
./examples/src/ExampleApplication.cpp:
[line:201] pBuffer
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels