Skip to content

Commit a36d996

Browse files
committed
gfx/d3d10: null cbuffers[j].uniforms after free to match d3d11/d3d12 style
d3d10_free_shader_preset's inner loop frees the uniform buffer behind each d3d10->pass[i].semantics.cbuffers[j].uniforms but does not null the field out afterwards: free(d3d10->pass[i].semantics.cbuffers[j].uniforms); Release(d3d10->pass[i].buffers[j]); The sibling d3d11_free_shader_preset and d3d12_free_shader_preset both null the field: free(d3d11->pass[i].semantics.cbuffers[j].uniforms); d3d11->pass[i].semantics.cbuffers[j].uniforms = NULL; Release(d3d11->pass[i].buffers[j]); In practice the d3d10 version gets away with the omission because the outer loop is followed by 'memset(d3d10->pass, 0, sizeof(d3d10->pass))' which zeroes every pass's semantics block, including the uniforms pointers, before the function returns. So the end state is correct and currently-reachable code does not observe the dangling pointer. The inconsistency is still a hazard: if a future change adds an early-return inside the inner loop, splits the loop body, or reorders the memset away from the end, the transient dangling pointer becomes persistent. Match the other two drivers' discipline so all three free paths look the same and the pattern is less fragile to future edits. No behaviour change on the currently-reachable paths. Thread-safety: unchanged. d3d10_free_shader_preset runs on whatever thread tears the shader preset down (typically the video thread); no synchronisation introduced or affected.
1 parent 9441128 commit a36d996

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

gfx/drivers/d3d10.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ static void d3d10_free_shader_preset(d3d10_video_t* d3d10)
15951595
for (j = 0; j < SLANG_CBUFFER_MAX; j++)
15961596
{
15971597
free(d3d10->pass[i].semantics.cbuffers[j].uniforms);
1598+
d3d10->pass[i].semantics.cbuffers[j].uniforms = NULL;
15981599
Release(d3d10->pass[i].buffers[j]);
15991600
}
16001601
}

0 commit comments

Comments
 (0)