Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit 37531fa

Browse files
Patrick Lerda1ace
authored andcommitted
nouveau: fix nouveau_heap_destroy() memory leak
Indeed, this function was not processing the linked allocated list. For instance, this issue is triggered with "piglit/bin/hiz-depth-read-fbo-d24-s0 -auto": Indirect leak of 40 byte(s) in 1 object(s) allocated from: #0 0x7f6795638987 in calloc (/usr/lib64/libasan.so.6+0xb1987) android-rpi#1 0x7f678bac13b9 in nouveau_heap_alloc ../src/gallium/drivers/nouveau/nouveau_heap.c:64 android-rpi#2 0x7f678bb6c7e4 in nv50_program_upload_code ../src/gallium/drivers/nouveau/nv50/nv50_program.c:490 android-rpi#3 0x7f678bb83b92 in nv50_vertprog_validate ../src/gallium/drivers/nouveau/nv50/nv50_shader_state.c:161 #4 0x7f678bba3000 in nv50_state_validate ../src/gallium/drivers/nouveau/nv50/nv50_state_validate.c:552 #5 0x7f678bba3c4d in nv50_state_validate_3d ../src/gallium/drivers/nouveau/nv50/nv50_state_validate.c:575 #6 0x7f678b9e3e92 in nv50_blit_3d ../src/gallium/drivers/nouveau/nv50/nv50_surface.c:1444 #7 0x7f678b9e3e92 in nv50_blit ../src/gallium/drivers/nouveau/nv50/nv50_surface.c:1832 #8 0x7f678a0b378a in blit_to_staging ../src/mesa/state_tracker/st_cb_readpixels.c:337 #9 0x7f678a0b7358 in st_ReadPixels ../src/mesa/state_tracker/st_cb_readpixels.c:516 #10 0x7f6789f82005 in read_pixels ../src/mesa/main/readpix.c:1178 #11 0x7f6789f82005 in _mesa_ReadnPixelsARB ../src/mesa/main/readpix.c:1195 #12 0x7f6789f82ac0 in _mesa_ReadPixels ../src/mesa/main/readpix.c:1210 ... SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s). Fixes: 67635a0 ("nouveau: get rid of tabs") Signed-off-by: Patrick Lerda <[email protected]> Reviewed-by: Karol Herbst <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23592> (cherry picked from commit 1980934)
1 parent 6d48542 commit 37531fa

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

.pick_status.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@
22632263
"description": "nouveau: fix nouveau_heap_destroy() memory leak",
22642264
"nominated": true,
22652265
"nomination_type": 1,
2266-
"resolution": 0,
2266+
"resolution": 1,
22672267
"main_sha": null,
22682268
"because_sha": "67635a0a713e54939f1f72ba8db2b3099988a925"
22692269
},

src/gallium/drivers/nouveau/nouveau_heap.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ nouveau_heap_init(struct nouveau_heap **heap,
4444
void
4545
nouveau_heap_destroy(struct nouveau_heap **heap)
4646
{
47-
if (!*heap)
48-
return;
49-
free(*heap);
47+
struct nouveau_heap *current = *heap;
48+
49+
while (current) {
50+
struct nouveau_heap *const next = current->next;
51+
free(current);
52+
current = next;
53+
}
54+
5055
*heap = NULL;
5156
}
5257

src/gallium/drivers/nouveau/nvc0/nvc0_screen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ nvc0_screen_destroy(struct pipe_screen *pscreen)
632632
nouveau_bo_ref(NULL, &screen->fence.bo);
633633
nouveau_bo_ref(NULL, &screen->poly_cache);
634634

635-
nouveau_heap_destroy(&screen->lib_code);
635+
nouveau_heap_free(&screen->lib_code);
636636
nouveau_heap_destroy(&screen->text_heap);
637637

638638
FREE(screen->tic.entries);
@@ -883,7 +883,7 @@ nvc0_screen_resize_text_area(struct nvc0_screen *screen, struct nouveau_pushbuf
883883
nouveau_bo_ref(NULL, &screen->text);
884884
screen->text = bo;
885885

886-
nouveau_heap_destroy(&screen->lib_code);
886+
nouveau_heap_free(&screen->lib_code);
887887
nouveau_heap_destroy(&screen->text_heap);
888888

889889
/* XXX: getting a page fault at the end of the code buffer every few

0 commit comments

Comments
 (0)