Skip to content

Commit

Permalink
testpat: Fix memory mapping in threaded drawing
Browse files Browse the repository at this point in the history
The IFramebuffer::map() function is not thread-safe, which is why the
threaded implementation of draw_test_pattern_impl() maps all planes
before starting to draw. A typo slipped in the code, resulting in only
plane 0 being mapped. This didn't result in an immediate segfault, as
drawing operations in the worker threads map the remaining planes.
However, due to the implementation of DumbFramebuffer::map(), this can
result in the same plane being mapped multiple times, with only one of
the mapping recorded in the mapping cache. The other mappings are then
leaked, leading not only to extra memory consumption, but also to the
DRM device never being released even after the destruction of the Card
object.

Fix this.

Fixes: 40d9606 ("Revert "testpat: remove threaded drawing"")
Signed-off-by: Laurent Pinchart <[email protected]>
Signed-off-by: Tomi Valkeinen <[email protected]>
  • Loading branch information
pinchartl authored and tomba committed Nov 15, 2023
1 parent c23e754 commit 9ae90ce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion kms++util/src/testpat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void draw_test_pattern_impl(IFramebuffer& fb, YUVType yuvt)

// Create the mmaps before starting the threads
for (unsigned i = 0; i < fb.num_planes(); ++i)
fb.map(0);
fb.map(i);

unsigned num_threads = thread::hardware_concurrency();
vector<thread> workers;
Expand Down

0 comments on commit 9ae90ce

Please sign in to comment.