Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
startMoveRequest()andstartFindRequest()indcmqrdb/libsrc/dcmqrdbi.ccleak memory on several error return paths. One reproducible path is an invalidQueryRetrieveLevelvalue in a C-GET or C-MOVE request, which causes the function to return early without freeingelem.PValueFieldor the accumulatedfindRequestList. Since the server does not crash on this error, repeated requests can cause cumulative memory growth.Problem & Root Cause
Both functions parse the DICOM dataset in a loop, allocating each tag's value with
malloc(line 2066):The normal path frees this at the end of the loop body (line 2136). However, four early-return paths in
startMoveRequest()skip this cleanup:elem.PValueField+ accumulatedfindRequestListentries. Reproducible with a malformed network request.mallocfailure (line 2067) — leaks accumulatedfindRequestList.new DB_ElementListfailure (line 2123) — leakselem.PValueField+ accumulatedfindRequestList.DB_CounterListallocation failure (line 2231) — leaks accumulatedmoveCounterListentries, and also misses aDB_unlock()call.startFindRequest()has three analogous paths. It already freeselem.PValueFieldon its invalid-level path, but still leaks thefindRequestList.Notably, the
!qrLevelFoundpath at line 2142 already has correct cleanup (DB_FreeElementList+ NULL), providing an existing cleanup pattern.Changes
dcmqrdb/libsrc/dcmqrdbi.ccstartMoveRequest(), paths 1–3: add the appropriate resource cleanup (free(elem.PValueField)and/orDB_FreeElementList(handle_->findRequestList)) before each affected error return, matching the existing cleanup at line 2142.startMoveRequest(), path 4: free accumulatedmoveCounterListentries and add the missingDB_unlock()call before the error return.startFindRequest(): addDB_FreeElementList(handle_->findRequestList); handle_->findRequestList = NULL;(andfree(elem.PValueField)where applicable) before each affected error return.Path 1 fix (invalid query level in
startMoveRequest):The same pattern applies to the other early-return paths in both functions, with each path freeing the resources that have been allocated up to that point.
Verification
Built dcmqrscp with AddressSanitizer (
-fsanitize=address) on currentmaster(da4682c). Sent 20 C-GET requests withQueryRetrieveLevel = "INVALID"via pynetdicom:The invalid QueryRetrieveLevel path in
startMoveRequest()was verified dynamically using AddressSanitizer. The remaining error paths were identified through source code inspection.Before fix — LeakSanitizer output on dcmqrscp shutdown:
20 requests × 9 bytes (8-byte DICOM CS-padded value + 1-byte null terminator) = 180 bytes, matching the LeakSanitizer report.
After fix — same test, clean exit, no LeakSanitizer output:
The changes are limited to error-handling paths and do not modify normal request processing.
Thanks ^^