Commit 9441128
committed
gfx/font_driver: plug renderer-state leak on OOM in font_driver_init_first
font_driver_init_first starts by calling font_init_first (or
video_thread_font_init in the threaded-video case), which on success
populates font_driver and font_handle. That handle owns the raster
font's allocated state - glyph atlas texture, GL names, D3D COM
objects, etc. - allocated and held inside the chosen renderer
(gl2_raster_font / d3d11_font / vulkan_raster_font / ...).
Only after that succeeds do we malloc the small wrapper struct
(font_data_t). Before this commit, if that wrapper malloc failed,
the function returned NULL directly and the entire raster-font
state was orphaned with no path to free it. Cores that hit OOM
during font init would leak that state on every failed attempt.
Also refactors font_driver_free's renderer-side teardown into a
shared helper, font_driver_release_renderer_state, so both the
normal teardown path and the new OOM cleanup path handle the
threaded-vs-non-threaded dispatch the same way. This matters:
renderer->free cannot be called on the main thread when threaded
video is active, because it touches GPU state owned by the video
thread (GL context, D3D ImmediateContext, D3D12 fence, Vulkan
command buffer recording). The existing teardown already dispatches
via video_thread_texture_handle + font_driver_free_wrap; the OOM
path now takes the same route.
Before the refactor, font_driver_free had its own inline thread-
dispatch block with the safety rationale as a comment. That comment
is preserved verbatim on the shared helper so the knowledge isn't
lost.
Thread-safety:
- Non-threaded video: renderer->free runs synchronously on the
caller's thread. Identical to the previous behaviour for both
call sites.
- Threaded video: renderer->free is dispatched to the video thread
via video_thread_texture_handle. For the OOM cleanup path this
is a behaviour fix (previous code didn't free at all), not a
change to the teardown path itself. video_thread_texture_handle
is documented self-safe: falls back to direct call if the
wrapper isn't active, calls func directly if already on the
video thread.
Control flow in font_driver_free is slightly reorganised - the
original code had an early 'free(font); return;' inside the threaded
branch and let the non-threaded path fall through. The refactor
unifies the post-renderer-free cleanup (NULL ivars + free(font)) at
the end of the function body. Equivalent in behaviour, easier to
read.
No functional change to font_driver_init_first's success path; the
wrapper struct allocation, field assignment, and return are
unchanged.1 parent c0f6fc4 commit 9441128
1 file changed
Lines changed: 67 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
918 | 918 | | |
919 | 919 | | |
920 | 920 | | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
921 | 974 | | |
922 | 975 | | |
923 | 976 | | |
924 | 977 | | |
925 | | - | |
926 | 978 | | |
927 | 979 | | |
928 | 980 | | |
929 | 981 | | |
930 | 982 | | |
931 | | - | |
932 | 983 | | |
933 | | - | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
| 984 | + | |
| 985 | + | |
978 | 986 | | |
979 | 987 | | |
980 | 988 | | |
| |||
1014 | 1022 | | |
1015 | 1023 | | |
1016 | 1024 | | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
1017 | 1037 | | |
1018 | 1038 | | |
1019 | 1039 | | |
| |||
0 commit comments