Mercurial > hg > orthanc-python
changeset 152:a6b4e0abe532 cmove2
fix leaking of MoveDriver
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 29 Feb 2024 11:31:47 +0100 |
parents | 566df919b286 |
children | a8408ef2b2d8 |
files | NEWS Sources/DicomScpCallbacks.cpp |
diffstat | 2 files changed, 13 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Tue Feb 27 16:13:08 2024 +0100 +++ b/NEWS Thu Feb 29 11:31:47 2024 +0100 @@ -2,6 +2,13 @@ =============================== * Fix signature of "orthanc.RestOutput.SendHttpStatus()" +* Added orthanc.RegisterMoveCallback2() that takes 4 callbacks like the + original C SDK function. This allows you to implement a correct handling + of the C-Move sub-operations count in the GetMoveSize(). The ApplyMove() + must now handle a single sub-operation at a time. + The legacy orthanc.RegisterMoveCallback() always considers that there is a single + sub-operation and we have observed modalities complaining that the number of + sub-operations was not matching the number of instances sent. Version 4.1 (2023-08-30)
--- a/Sources/DicomScpCallbacks.cpp Tue Feb 27 16:13:08 2024 +0100 +++ b/Sources/DicomScpCallbacks.cpp Thu Feb 29 11:31:47 2024 +0100 @@ -541,8 +541,10 @@ PythonObject args(lock, PyTuple_New(0)); // Note: the result is not attached to the PythonLock because we want it to survive after this call since - // the result is the python move driver that will be passed as first argument to GetMoveSize, Apply and Free - std::unique_ptr<PyObject> result(PyObject_Call(createMoveScpDriverCallback_, args.GetPyObject(), kw.GetPyObject())); + // the result is the python move driver that will be passed as first argument to GetMoveSize, Apply and Free. + // After the PyObject_Call, result's ref count is 1 -> no need to add a reference but we need to decref explicitely + // to delete the object at the end of the move. + PyObject* result = PyObject_Call(createMoveScpDriverCallback_, args.GetPyObject(), kw.GetPyObject()); OrthancPluginErrorCode code = lock.CheckCallbackSuccess("Python C-MOVE SCP callback (Create)"); if (code != OrthancPluginErrorCode_Success) @@ -550,10 +552,7 @@ throw OrthancPlugins::PluginException(code); } - // make sure it survives after this call - Py_INCREF(result.get()); - - return result.release(); + return result; } catch (OrthancPlugins::PluginException& e) { @@ -623,7 +622,7 @@ lock.CheckCallbackSuccess("Python C-MOVE SCP callback (Free)"); - Py_DECREF(moveDriver); + Py_DECREF(moveDriver); // remove the initial reference -> this will delete the Python Object when we exit this function }