语音识别 sdk线程未正确退出,内存泄露
这shi什么鬼 发布于2019-12 浏览:1264 回复:2
0
收藏

语音识别标准版linux C++ SDK ,使用在提供的C++demo中,识别结束调用bds::BDSpeechSDK::do_cleanup();函数。发现在销毁之前线程后又创建了30个线程,未正确释放。

存在内存泄露问题。

下附为gdb调试的log,可直观看到线程数变化。最后一个断点为bds::BDSpeechSDK::do_cleanup()函数前。

请问有人遇到过这个问题吗?

 


[ty@localhost asr]$ gdb main
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-47.el6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/ty/develop/asr-linux-cpp/sample/asr/main...done.
(gdb) b main.cpp:418
Breakpoint 1 at 0x4127f4: file ./src/main.cpp, line 418.
(gdb) b main.cpp:428
Breakpoint 2 at 0x412850: file ./src/main.cpp, line 428.
(gdb) r
Starting program: /home/ty/develop/asr-linux-cpp/sample/asr/main
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff7fe6700 (LWP 106239)]

Breakpoint 1, main (argc=1, argv=0x7fffffffe5b8) at ./src/main.cpp:418
418 for (int i = 0; i < THREAD_NUM; ++i) {
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64 libgcc-4.4.7-23.el6.x86_64 libstdc++-4.4.7-23.el6.x86_64
(gdb) info threads
Id Target Id Frame
2 Thread 0x7ffff7fe6700 (LWP 106239) "main" 0x00000030eb4e8b31 in clone ()
from /lib64/libc.so.6
* 1 Thread 0x7ffff7fe8720 (LWP 106235) "main" main (argc=1,
argv=0x7fffffffe5b8) at ./src/main.cpp:418
(gdb) n
419 int ret = pthread_join(thread_ids[i], NULL); // 等待所有线程结束
(gdb) c
Continuing.
Will recognize file: ./pcm/16k-0.pcm
sdk version :3.0.0.30628d440
[New Thread 0x7ffff75e5700 (LWP 106240)]
[New Thread 0x7ffff6be4700 (LWP 106241)]
[New Thread 0x7ffff61e3700 (LWP 106242)]
[New Thread 0x7ffff57e2700 (LWP 106243)]
[New Thread 0x7ffff4de1700 (LWP 106244)]
[New Thread 0x7fffeffff700 (LWP 106245)]
[New Thread 0x7fffef5fe700 (LWP 106246)]
[New Thread 0x7fffeebfd700 (LWP 106247)]
[New Thread 0x7fffee1fc700 (LWP 106248)]
[New Thread 0x7fffed7fb700 (LWP 106249)]
[New Thread 0x7fffecdfa700 (LWP 106250)]
[New Thread 0x7fffec3f9700 (LWP 106251)]
[New Thread 0x7fffeb9f8700 (LWP 106252)]
[New Thread 0x7fffeaff7700 (LWP 106253)]
[New Thread 0x7fffea5f6700 (LWP 106254)]
[New Thread 0x7fffe9bf5700 (LWP 106255)]
[New Thread 0x7fffe91f4700 (LWP 106256)]
[New Thread 0x7fffe87f3700 (LWP 106257)]
[New Thread 0x7fffe7df2700 (LWP 106258)]
[New Thread 0x7fffe73f1700 (LWP 106259)]
[New Thread 0x7fffe69f0700 (LWP 106260)]
[New Thread 0x7fffe5fef700 (LWP 106261)]
[New Thread 0x7fffe55ee700 (LWP 106262)]
[New Thread 0x7fffe4bed700 (LWP 106263)]
[New Thread 0x7fffe41ec700 (LWP 106264)]
[New Thread 0x7fffe37eb700 (LWP 106265)]
[New Thread 0x7fffe2dea700 (LWP 106266)]
[New Thread 0x7fffe23e9700 (LWP 106267)]
[New Thread 0x7fffe19e8700 (LWP 106268)]
[New Thread 0x7fffe0fe7700 (LWP 106269)]
[GlobalThreadPool::GlobalThreadPool] alloc thread num:30
[2019-11-08 02:54:32.292]识别工作开始
[2019-11-08 02:54:32.660]检测到开始说话
[2019-11-08 02:54:33.636]patial result: {"results_recognition":["今"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"raf":96,"result":{"word":["今"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:01.110"}
[2019-11-08 02:54:34.000]patial result: {"results_recognition":["今天"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"raf":128,"result":{"word":["今天"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:01.439"}
[2019-11-08 02:54:34.157]patial result: {"results_recognition":["今天天"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"raf":144,"result":{"word":["今天天"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:01.590"}
[2019-11-08 02:54:34.478]patial result: {"results_recognition":["今天天气"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"raf":176,"result":{"word":["今天天气"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:01.889"}
[2019-11-08 02:54:34.687]patial result: {"results_recognition":["今天天气怎"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"raf":192,"result":{"word":["今天天气怎"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:02.800"}
[2019-11-08 02:54:35.405]final result: {"results_recognition":["今天天气怎样?"],"origin_result":{"corpus_no":6756846321363792927,"err_no":0,"result":{"word":["今天天气怎样?"]},"sn":"A6D570B5-32CF-4A55-A681-5AE788D6E4FE"},"sn_start_time":"00:00.340","sn_end_time":"00:02.509"}
其它状态14
[2019-11-08 02:54:35.445]push_audio finish
其它状态16
其它状态14
识别完成
[2019-11-08 02:54:35.774]thread[0] finish
[Thread 0x7ffff7fe6700 (LWP 106239) exited]

Breakpoint 2, main (argc=1, argv=0x7fffffffe5b8) at ./src/main.cpp:428
428 bds::BDSpeechSDK::do_cleanup();
(gdb) info threads
Id Target Id Frame
32 Thread 0x7fffe0fe7700 (LWP 106269) "main"
0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 ()
from /lib64/libpthread.so.0
31 Thread 0x7fffe19e8700 (LWP 106268) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
30 Thread 0x7fffe23e9700 (LWP 106267) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
29 Thread 0x7fffe2dea700 (LWP 106266) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
28 Thread 0x7fffe37eb700 (LWP 106265) "main" 0x00000030eb4accdd in nanosleep () from /lib64/libc.so.6
27 Thread 0x7fffe41ec700 (LWP 106264) "main" 0x00000030eb4accdd in nanosleep () from /lib64/libc.so.6
26 Thread 0x7fffe4bed700 (LWP 106263) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
25 Thread 0x7fffe55ee700 (LWP 106262) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
24 Thread 0x7fffe5fef700 (LWP 106261) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
---Type to continue, or q to quit---
23 Thread 0x7fffe69f0700 (LWP 106260) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
22 Thread 0x7fffe73f1700 (LWP 106259) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
21 Thread 0x7fffe7df2700 (LWP 106258) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
20 Thread 0x7fffe87f3700 (LWP 106257) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
19 Thread 0x7fffe91f4700 (LWP 106256) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
18 Thread 0x7fffe9bf5700 (LWP 106255) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
17 Thread 0x7fffea5f6700 (LWP 106254) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
16 Thread 0x7fffeaff7700 (LWP 106253) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
15 Thread 0x7fffeb9f8700 (LWP 106252) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
14 Thread 0x7fffec3f9700 (LWP 106251) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
---Type to continue, or q to quit---
13 Thread 0x7fffecdfa700 (LWP 106250) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
12 Thread 0x7fffed7fb700 (LWP 106249) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
11 Thread 0x7fffee1fc700 (LWP 106248) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
10 Thread 0x7fffeebfd700 (LWP 106247) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
9 Thread 0x7fffef5fe700 (LWP 106246) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
8 Thread 0x7fffeffff700 (LWP 106245) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
7 Thread 0x7ffff4de1700 (LWP 106244) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
6 Thread 0x7ffff57e2700 (LWP 106243) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
5 Thread 0x7ffff61e3700 (LWP 106242) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
4 Thread 0x7ffff6be4700 (LWP 106241) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
---Type to continue, or q to quit---
3 Thread 0x7ffff75e5700 (LWP 106240) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 1 Thread 0x7ffff7fe8720 (LWP 106235) "main" main (argc=1,
argv=0x7fffffffe5b8) at ./src/main.cpp:428
(gdb) n
[Thread 0x7fffe41ec700 (LWP 106264) exited]
[Thread 0x7fffe37eb700 (LWP 106265) exited]
[Thread 0x7fffe0fe7700 (LWP 106269) exited]
[Thread 0x7fffe19e8700 (LWP 106268) exited]
[Thread 0x7fffe23e9700 (LWP 106267) exited]
[Thread 0x7fffe2dea700 (LWP 106266) exited]
[Thread 0x7fffe4bed700 (LWP 106263) exited]
[Thread 0x7fffe55ee700 (LWP 106262) exited]
[Thread 0x7fffe5fef700 (LWP 106261) exited]
[Thread 0x7fffe69f0700 (LWP 106260) exited]
[Thread 0x7fffe73f1700 (LWP 106259) exited]
[Thread 0x7fffe7df2700 (LWP 106258) exited]
[Thread 0x7fffe87f3700 (LWP 106257) exited]
[Thread 0x7fffe91f4700 (LWP 106256) exited]
[Thread 0x7fffe9bf5700 (LWP 106255) exited]
[Thread 0x7fffea5f6700 (LWP 106254) exited]
[Thread 0x7fffeaff7700 (LWP 106253) exited]
[Thread 0x7fffeb9f8700 (LWP 106252) exited]
[Thread 0x7fffec3f9700 (LWP 106251) exited]
[Thread 0x7fffecdfa700 (LWP 106250) exited]
[Thread 0x7fffed7fb700 (LWP 106249) exited]
[Thread 0x7fffee1fc700 (LWP 106248) exited]
[Thread 0x7fffeebfd700 (LWP 106247) exited]
[Thread 0x7fffef5fe700 (LWP 106246) exited]
[Thread 0x7fffeffff700 (LWP 106245) exited]
[Thread 0x7ffff4de1700 (LWP 106244) exited]
[Thread 0x7ffff57e2700 (LWP 106243) exited]
[Thread 0x7ffff61e3700 (LWP 106242) exited]
[Thread 0x7ffff6be4700 (LWP 106241) exited]
[Thread 0x7ffff75e5700 (LWP 106240) exited]
[New Thread 0x7ffff75e5700 (LWP 106270)]
[New Thread 0x7ffff6be4700 (LWP 106271)]
[New Thread 0x7ffff61e3700 (LWP 106272)]
[New Thread 0x7ffff7fe6700 (LWP 106273)]
[New Thread 0x7ffff57e2700 (LWP 106274)]
[New Thread 0x7ffff4de1700 (LWP 106275)]
[New Thread 0x7fffeffff700 (LWP 106276)]
[New Thread 0x7fffef5fe700 (LWP 106277)]
[New Thread 0x7fffeebfd700 (LWP 106278)]
[New Thread 0x7fffee1fc700 (LWP 106279)]
[New Thread 0x7fffed7fb700 (LWP 106280)]
[New Thread 0x7fffecdfa700 (LWP 106281)]
[New Thread 0x7fffec3f9700 (LWP 106282)]
[New Thread 0x7fffeb9f8700 (LWP 106283)]
[New Thread 0x7fffeaff7700 (LWP 106284)]
[New Thread 0x7fffea5f6700 (LWP 106285)]
[New Thread 0x7fffe9bf5700 (LWP 106286)]
[New Thread 0x7fffe91f4700 (LWP 106287)]
[New Thread 0x7fffe87f3700 (LWP 106288)]
[New Thread 0x7fffe7df2700 (LWP 106289)]
[New Thread 0x7fffe73f1700 (LWP 106290)]
[New Thread 0x7fffe69f0700 (LWP 106291)]
[New Thread 0x7fffe5fef700 (LWP 106292)]
[New Thread 0x7fffe55ee700 (LWP 106293)]
[New Thread 0x7fffe4bed700 (LWP 106294)]
[New Thread 0x7fffe41ec700 (LWP 106295)]
[New Thread 0x7fffe37eb700 (LWP 106296)]
[New Thread 0x7fffe2dea700 (LWP 106297)]
[New Thread 0x7fffe23e9700 (LWP 106298)]
[New Thread 0x7fffe19e8700 (LWP 106299)]
429 return 0;
(gdb) info threads
Id Target Id Frame
62 Thread 0x7fffe19e8700 (LWP 106299) "main" 0x00000030eb4e8b31 in clone ()
from /lib64/libc.so.6
61 Thread 0x7fffe23e9700 (LWP 106298) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
60 Thread 0x7fffe2dea700 (LWP 106297) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
59 Thread 0x7fffe37eb700 (LWP 106296) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
58 Thread 0x7fffe41ec700 (LWP 106295) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
57 Thread 0x7fffe4bed700 (LWP 106294) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
56 Thread 0x7fffe55ee700 (LWP 106293) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
55 Thread 0x7fffe5fef700 (LWP 106292) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
54 Thread 0x7fffe69f0700 (LWP 106291) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
53 Thread 0x7fffe73f1700 (LWP 106290) "main" 0x00000030eb80b5bc in pthread_c---Type to continue, or q to quit---
ond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
52 Thread 0x7fffe7df2700 (LWP 106289) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
51 Thread 0x7fffe87f3700 (LWP 106288) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
50 Thread 0x7fffe91f4700 (LWP 106287) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
49 Thread 0x7fffe9bf5700 (LWP 106286) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
48 Thread 0x7fffea5f6700 (LWP 106285) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
47 Thread 0x7fffeaff7700 (LWP 106284) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
46 Thread 0x7fffeb9f8700 (LWP 106283) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
45 Thread 0x7fffec3f9700 (LWP 106282) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
44 Thread 0x7fffecdfa700 (LWP 106281) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
43 Thread 0x7fffed7fb700 (LWP 106280) "main" 0x00000030eb80b5bc in pthread_c---Type to continue, or q to quit---
ond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
42 Thread 0x7fffee1fc700 (LWP 106279) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
41 Thread 0x7fffeebfd700 (LWP 106278) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
40 Thread 0x7fffef5fe700 (LWP 106277) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
39 Thread 0x7fffeffff700 (LWP 106276) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
38 Thread 0x7ffff4de1700 (LWP 106275) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
37 Thread 0x7ffff57e2700 (LWP 106274) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
36 Thread 0x7ffff7fe6700 (LWP 106273) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
35 Thread 0x7ffff61e3700 (LWP 106272) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
34 Thread 0x7ffff6be4700 (LWP 106271) "main" 0x00000030eb80b5bc in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
33 Thread 0x7ffff75e5700 (LWP 106270) "main" 0x00000030eb80b5bc in pthread_c---Type to continue, or q to quit---
ond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 1 Thread 0x7ffff7fe8720 (LWP 106235) "main" main (argc=1,
argv=0x7fffffffe5b8) at ./src/main.cpp:429
(gdb)
(gdb)
(gdb) q

 

收藏
点赞
0
个赞
共2条回复 最后由fujiayi1984回复于2019-12
#3fujiayi1984回复于2019-12

目前研发确认下版本优化这个不必要的初始化

0
#2fujiayi1984回复于2019-12

在 do_clieanup的时候,先销毁之前的线程池,然后创建一个相同的,空闲的线程池。

新的线程池可以确定不会导致内存泄露

0
TOP
切换版块