Skip to content

util/mesa-db: fix FD leaks to child processes

Simon Ser requested to merge emersion/mesa:cache-db-cloexec into main

What does this MR do and why?

Mesa is used in settings where the process forks and execs another process (e.g. Wayland compositor spawning a client). Any FD opened by Mesa will leak to child processes unless it has the close-on-exec (CLOEXEC) flag set.

A few spots in the cache DB were using plain fopen(3). This function doesn't set the CLOEXEC flag, and I'm seeing a few hundred FD leaks to child processes such as:

208 -> /home/simon/.cache/mesa_shader_cache_db/part41/mesa_cache.idx
209 -> /home/simon/.cache/mesa_shader_cache_db/part42/mesa_cache.db

Add a helper to fopen(3) with the CLOEXEC flag set. Use that thin helper over the GNU 'e' flag for portability.

Fixes: 32211788 ("util/disk_cache: Add new mesa-db cache type")

cc @digetx @xexaxo @tarceri

Merge request reports

Loading