Kmemleak in vi_capture_shutdown

Hello,

I am working with jetpack-6.1(rev1) on Orin NX.
After running twice a simple image capture test program (and waiting ten minutes for kmemleak to make its job), kmemleak has detected a memory leak originating from

        capture->unpins_list =
                vzalloc(setup->queue_depth * sizeof(*capture->unpins_list));

in vi_capture_setup() in drivers/media/platform/tegra/camera/fusa-capture/capture-vi.c

I tracked it down to this line

        kfree(capture);

in vi_capture_shutdown() in the same file, where ‘capture’ is freed without first freeing ‘unpins_list’.

I have added a trivial fix

@@ -551,6 +552,13 @@ void vi_capture_shutdown(
                vfree(capture->unpins_list);
                capture->unpins_list = NULL;
        }
+       if (capture->unpins_list) {
+               printk("kfree(capture = %p) with non-NULL (%p) unpins_list\n",
+                       capture, capture->unpins_list);
+               printk("force freeing unpins_list\n");
+               vfree(capture->unpins_list);
+               capture->unpins_list = NULL;
+       }
        kfree(capture);
        chan->capture_data = NULL;
 }

which suppresses the memory leak on ‘unpins_list’, but thereafter kmemleaks reports many more memory leaks, which reveals that ‘unpins_list’ itself contains pointers to many other allocated memory zones.

Here is my test program. Adjust it based on your sensor characteristics. Memory leak happens if run twice or more.

v4l2-ctl -d /dev/video0 -p 67.200
v4l2-ctl -d /dev/video0 --stream-mmap=3 --stream-count=256 --set-fmt-video=width=2472,height=2064,pixelformat=GREY

Nvidia experts, can you provide a clean fix ?

Have a nice day

Apply the patches from below link to verify.

Hello ShaneCCC,

I attempted to apply those patches, but

Do you have another suggestion ?

Have you reproduced the problem internally ?

Best regards

There is no update from you for a period, assuming this is not an issue anymore.
Hence, we are closing this topic. If need further support, please open a new one.
Thanks
~0521

Does the original leak large memory to cause problem?