Skip to content
Snippets Groups Projects

nvdec: fix multiple call to cuInit

Merged Alexandre Janniaux requested to merge alexandre-janniaux/vlc:nvdec-init-once/1 into master
All threads resolved!

/!\ Disclamer: because of the usage of vlc_once_t, I'm not sure whether the device pointer used for initialization needs to be atomic or not. Feel free to indicate whether this incorrect, I haven't checked yet.

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)
Edited by Alexandre Janniaux

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Steve Lhomme resolved all threads

    resolved all threads

    • Resolved by Rémi Denis-Courmont

      vlc_once() is supposed to have non-first calls wait for completion of the first call. It would be pretty useless elsewise.

      Now that we no longer depend on pthread_once(), we could improve the interface, so that it would take a data pointer and avoid relying on globals, but that wouldn't help much at all in this particular case.

      Note that this fix won't work if the procesd uses CUDA through some other path, outside LibVLC or underneath a contrib (maybe FFmpeg could?).

      It also will continue to leak if LibVLC is destroyed and recreated multiple times, as the nvdec module would be unloaded, depending on the platform.

  • Alexandre Janniaux resolved all threads

    resolved all threads

  • added 43 commits

    Compare with previous version

  • Alexandre Janniaux marked this merge request as ready

    marked this merge request as ready

  • added 1 commit

    • 1c37c0f1 - nvdec: fix multiple call to cuInit

    Compare with previous version

  • Rémi Denis-Courmont resolved all threads

    resolved all threads

  • MR Acceptance result

    :tada: This MergeRequest has been Accepted! Congratulations.

    MR acceptance checks details:

    • :white_check_mark: MR should be considered mergeable by Gitlab
    • :white_check_mark: Last pipeline should be successful
    • :white_check_mark: MergeRequest should have at least one external review and/or vote
    • :white_check_mark: All threads should be resolved, and score >= 0
    • :white_check_mark: MergeRequest should have no activity (threads/votes) for (24h/24h)

    This message was automatically generated by homer-bot.

  • added 30 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading