# HG changeset patch # User Alain Mazy # Date 1709202707 -3600 # Node ID a6b4e0abe532f17d86d9ae0f9ce57f4437b6037a # Parent 566df919b286aed917da7ebd92c52ee3dec08f66 fix leaking of MoveDriver diff -r 566df919b286 -r a6b4e0abe532 NEWS --- 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) diff -r 566df919b286 -r a6b4e0abe532 Sources/DicomScpCallbacks.cpp --- 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 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 }