Skip to content

Commit

Permalink
Fix trackingFree() - do not add a not removed entry
Browse files Browse the repository at this point in the history
Do not add memory back to the tracker,
if it had not been removed.

Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
  • Loading branch information
ldorau committed Oct 15, 2024
1 parent b613ed4 commit 22aba19
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/provider/provider_tracking.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ static umf_result_t trackingAllocationMerge(void *hProvider, void *lowPtr,

static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) {
umf_result_t ret;
umf_result_t ret_remove;
umf_tracking_memory_provider_t *p =
(umf_tracking_memory_provider_t *)hProvider;

Expand All @@ -345,13 +346,13 @@ static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) {
// could allocate the memory at address `ptr` before a call to umfMemoryTrackerRemove
// resulting in inconsistent state.
if (ptr) {
ret = umfMemoryTrackerRemove(p->hTracker, ptr);
if (ret != UMF_RESULT_SUCCESS) {
ret_remove = umfMemoryTrackerRemove(p->hTracker, ptr);
if (ret_remove != UMF_RESULT_SUCCESS) {
// DO NOT return an error here, because the tracking provider
// cannot change behaviour of the upstream provider.
LOG_ERR("failed to remove the region from the tracker, ptr=%p, "
"size=%zu, ret = %d",
ptr, size, ret);
ptr, size, ret_remove);
}
}

Expand All @@ -371,6 +372,12 @@ static umf_result_t trackingFree(void *hProvider, void *ptr, size_t size) {
ret = umfMemoryProviderFree(p->hUpstream, ptr, size);
if (ret != UMF_RESULT_SUCCESS) {
LOG_ERR("upstream provider is failed to free the memory");
// Do not add memory back to the tracker,
// if it had not been removed.
if (ret_remove != UMF_RESULT_SUCCESS) {

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Analyze (windows-latest)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Fast builds / Fast builds (windows-latest, OFF, ON, OFF)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Sanitizers / cl and clang-cl on Windows (cl, cl, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Sanitizers / cl and clang-cl on Windows (clang-cl, clang-cl, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Debug, cl, cl, ON, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Debug, cl, cl, ON, ON, ON)

potentially uninitialized local variable 'ret_remove' used [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Debug, cl, cl, OFF, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Debug, cl, cl, OFF, ON, ON)

potentially uninitialized local variable 'ret_remove' used [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Release, cl, cl, ON, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Release, cl, cl, ON, ON, ON)

potentially uninitialized local variable 'ret_remove' used [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Release, cl, cl, OFF, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2019, Release, cl, cl, OFF, ON, ON)

potentially uninitialized local variable 'ret_remove' used [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2022, Debug, cl, cl, ON, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2022, Debug, cl, cl, OFF, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2022, Release, cl, cl, ON, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2022, Release, cl, cl, OFF, ON, ON)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Basic builds / Windows (windows-2022, Release, cl, cl, ON, OFF, OFF)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]

Check warning on line 377 in src/provider/provider_tracking.c

View workflow job for this annotation

GitHub Actions / Benchmarks / Benchmarks (windows-latest)

Using uninitialized memory 'ret_remove'.: Lines: 339, 340, 341, 348, 359, 360, 372, 373, 374, 377 [D:\a\unified-memory-framework\unified-memory-framework\build\src\umf.vcxproj]
return ret;
}

if (umfMemoryTrackerAdd(p->hTracker, p->pool, ptr, size) !=
UMF_RESULT_SUCCESS) {
LOG_ERR(
Expand Down

0 comments on commit 22aba19

Please sign in to comment.