[vlc-commits] [Git][videolan/vlc][master] nvdec: fix multiple call to cuInit

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Nov 21 22:06:56 UTC 2021



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
2dfb7d84 by Alexandre Janniaux at 2021-11-21T18:58:55+00:00
nvdec: fix multiple call to cuInit

Each cuInit is leaking memory, and cuInit is supposed to be called only
once. Ensure it through a vlc_once_t wrapper, but since the function
table needs to be loaded in order to call into cuda functions, forward
some available device for the initialization.

Below, there is two leaks because of the double decoder device
allocation in debug mode. The first leak is leaked once, and is still
there. The second and third leaks are now reduced to a single one.

Direct leak of 65536 byte(s) in 1 object(s) allocated from:
    #0 0x7febb6bf3652 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:164
    #1 0x7feb8b56828f  (<unknown module>)

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7febb6bf3459 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7feb89dc586a  (/home/alexandre/workspace/videolabs/vlc-meson/build-native/modules/.libs/libskins2_plugin.so+0x2f1086a)
    #2 0x7febb5f195c1 in decoder_device_Open ../../src/input/decoder_helpers.c:174
    #3 0x7febb5e67106 in vlc_module_load ../../src/modules/modules.c:243
    #4 0x7febb5f196e8 in vlc_decoder_device_Create ../../src/input/decoder_helpers.c:188
    #5 0x7febb60a7435 in vout_GetDevice ../../src/video_output/video_output.c:2244
    #6 0x7febb5ef7f26 in ModuleThread_GetDecoderDevice ../../src/input/decoder.c:608
    #7 0x7feba02ee139 in decoder_GetDecoderDevice ../../include/vlc_codec.h:304
    #8 0x7feba02fb51e in lavc_UpdateVideoFormat ../../modules/codec/avcodec/video.c:286
    #9 0x7feba0313ff7 in ffmpeg_GetFormat ../../modules/codec/avcodec/video.c:1682
    #10 0x7feb9f0bfe12  (/usr/lib/libavcodec.so.58+0x29ae12)

Direct leak of 56 byte(s) in 1 object(s) allocated from:
    #0 0x7febb6bf3459 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7feb8b5d386a  (<unknown module>)
    #2 0x7febb5f195c1 in decoder_device_Open ../../src/input/decoder_helpers.c:174
    #3 0x7febb5e67106 in vlc_module_load ../../src/modules/modules.c:243
    #4 0x7febb5f196e8 in vlc_decoder_device_Create ../../src/input/decoder_helpers.c:188
    #5 0x7febb60a7435 in vout_GetDevice ../../src/video_output/video_output.c:2244
    #6 0x7febb5ef7f26 in ModuleThread_GetDecoderDevice ../../src/input/decoder.c:608
    #7 0x7feba02ee139 in decoder_GetDecoderDevice ../../include/vlc_codec.h:304
    #8 0x7feba02fb51e in lavc_UpdateVideoFormat ../../modules/codec/avcodec/video.c:286
    #9 0x7feba0313ff7 in ffmpeg_GetFormat ../../modules/codec/avcodec/video.c:1682
    #10 0x7feb9f0bfe12  (/usr/lib/libavcodec.so.58+0x29ae12)

- - - - -


1 changed file:

- modules/hw/nvdec/nvdec.c


Changes:

=====================================
modules/hw/nvdec/nvdec.c
=====================================
@@ -1055,6 +1055,14 @@ static const struct vlc_decoder_device_operations dev_ops = {
     .close = DecoderContextClose,
 };
 
+static int cudaInitialized;
+static void initCuda(void *opaque)
+{
+    vlc_decoder_device *device = opaque;
+    decoder_device_nvdec_t *p_sys = device->opaque;
+    cudaInitialized = CALL_CUDA_DEV(cuInit, 0);
+}
+
 static int
 DecoderContextOpen(vlc_decoder_device *device, vout_window_t *window)
 {
@@ -1073,11 +1081,14 @@ DecoderContextOpen(vlc_decoder_device *device, vout_window_t *window)
         return VLC_EGENERIC;
     }
 
-    result = CALL_CUDA_DEV(cuInit, 0);
-    if (result != VLC_SUCCESS)
+    /* Use the current device functions if not initialized yet. */
+    static vlc_once_t init_once = VLC_STATIC_ONCE;
+    vlc_once(&init_once, initCuda, device);
+
+    if (cudaInitialized != CUDA_SUCCESS)
     {
         DecoderContextClose(device);
-        return result;
+        return VLC_EGENERIC;
     }
 
     result = CALL_CUDA_DEV(cuCtxCreate, &p_sys->cuCtx, 0, 0);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2dfb7d8418fa58009d405a6e5971877e7ef6e7c5

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/2dfb7d8418fa58009d405a6e5971877e7ef6e7c5
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list