首先,我要为未能将问题缩小到足以分享一个重现该错误的简短程序而道歉。
对“随机”的外部库 (FUSE) 调用会strncpy
覆盖shared_ptr<mutex>
我的代码中的 a,当我尝试锁定该互斥体时会导致段错误。我用 valgrind 运行我的程序,它没有发现任何内存错误(下面的 valgrind 标志)。当我在 gdb 中运行我的代码并在其上设置一个观察点时shared_ptr
,它会在调用 strncpy 时中断。gdb 表示所有strncpy
的参数(dest、src 和 nbytes)都已“优化”,这让我认为它正在为该调用使用未初始化的内存。我是否正确解释了这一点?知道可能是什么原因吗?
这是指针被覆盖时来自 gdb 的堆栈跟踪:
#0 __strncpy_ssse3 () at ../sysdeps/x86_64/multiarch/strcpy-ssse3.S:2482
#1 0x0000003245809094 in strncpy (__len=<optimized out>, __src=<optimized out>, __dest=<optimized out>) at /usr/include/bits/string3.h:120
#2 add_name (buf=<optimized out>, bufsize=<optimized out>, s=<optimized out>, name=<optimized out>) at fuse.c:907
#3 0x000000324580997c in try_get_path (f=<optimized out>, nodeid=<optimized out>, name=<optimized out>, path=<optimized out>, wnodep=<optimized out>, need_lock=<optimized out>) at fuse.c:956
#4 0x000000324580a281 in get_path_common (f=<optimized out>, nodeid=<optimized out>, name=<optimized out>, path=<optimized out>, wnode=<optimized out>) at fuse.c:1152
#5 0x0000003245812432 in fuse_lib_unlink (req=<optimized out>, parent=<optimized out>, name=<optimized out>) at fuse.c:1198
#6 0x0000003245817057 in fuse_ll_process_buf (data=0x6f5650, buf=0x7fffffffd850, ch=<optimized out>) at fuse_lowlevel.c:2441
#7 0x000000324581388f in fuse_session_loop (se=0x6f8410) at fuse_loop.c:40
#8 0x000000324580b698 in fuse_loop (f=<optimized out>) at fuse.c:4309
#9 0x000000324581bb8f in fuse_main_common (argc=<optimized out>, argv=<optimized out>, op=<optimized out>, op_size=<optimized out>, user_data=<optimized out>, compat=<optimized out>) at helper.c:355
#10 0x000000000046f1b6 in main (argc=4, argv=0x7fffffffdec8) at ../src/fuse.cpp:100
这是我运行 valgrind 的论点:
valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes