unispeech / unimrcp

Open source cross-platform implementation of MRCP protocol
http://www.unimrcp.org
Apache License 2.0
379 stars 167 forks source link

memory corrupted? #298

Closed lizhenghn123 closed 2 years ago

lizhenghn123 commented 3 years ago

Hi @achaloyan , I meet a question, which may be memory corruption. I debug as these:

image

and texts:

(gdb) bt
#0  synth_state_update (base=<optimized out>, message=0x7fe5b40182f8) at src/mrcp_synth_state_machine.c:570
#1  0x00007fe5db3a53ed in mrcp_server_msg_process (task=0xa5f318, msg=0x7fe5c00008c0) at src/mrcp_server.c:840
#2  0x00007fe5db3c144a in apt_task_msg_process (task=0xa5f318, msg=0x7fe5c00008c0) at src/apt_task.c:347
#3  0x00007fe5db3c183a in apt_consumer_task_run (task=<optimized out>) at src/apt_consumer_task.c:145
#4  0x00007fe5db3c0a20 in apt_task_run (thread_handle=0xa746a0, data=0xa5f318) at src/apt_task.c:594
#5  0x00007fe5da11dea5 in start_thread () from /lib64/libpthread.so.0
#6  0x00007fe5d9b448dd in ioperm () from /lib64/libc.so.6
#7  0x0000000000000000 in ?? ()
(gdb) p *message
$11 = {start_line = {message_type = MRCP_MESSAGE_TYPE_RESPONSE, version = MRCP_VERSION_2, length = 0, request_id = 1454635, method_name = {buf = 0x7fe5b4065730 "SPEAK", length = 4}, method_id = 3, status_code = MRCP_STATUS_CODE_SUCCESS, 
    request_state = MRCP_REQUEST_STATE_COMPLETE}, channel_id = {session_id = {buf = 0x7fe5b40657f0 "", length = 16}, resource_name = {buf = 0xa6d650 "speechsynth", length = 11}}, header = {generic_header_accessor = {data = 0x7fe5b40184e0, vtable = 0x7fe5db5db7e0 <vtable>}, 
    resource_header_accessor = {data = 0x7fe5b40185d8, vtable = 0x7fe5db5dba20 <vtable>}, header_section = {ring = {next = 0x7fe5b4018370, prev = 0x7fe5b4018370}, arr = 0x7fe5b40183b0, arr_size = 38}}, body = {buf = 0x0, length = 0}, resource = 0xa6d610, pool = 0x7fe5b4018278}

As you see :

  1. session_id is empty, which should't occur;
  2. method_name is "SPEAK", but method_id is "3", however the correctly method_id of "SPEAK" is 2, the method_id of "STOP" is 3, as in https://github.com/unispeech/unimrcp/blob/7c8703d6fe4d9816bf635b2848e3657606729fe3/libs/mrcp/resources/include/mrcp_synth_resource.h#L33

My veriosn is:

  1. unimrcp: 1.5
  2. tts plugin: demo-synth by your implement

And I add some logs to debug(print the pointer address of message and pool),

/** Process STOP request */
static apt_bool_t demo_synth_channel_stop(mrcp_engine_channel_t *channel, mrcp_message_t *request, mrcp_message_t *response)
{
    demo_synth_channel_t *synth_channel = channel->method_obj;
    /* store the request, make sure there is no more activity and only then send the response */
    synth_channel->stop_response = response;
    apt_log(APT_LOG_MARK, APT_PRIO_INFO, "demo_synth_channel_stop %s, %s, %0x, %0x", synth_channel->stop_response->channel_id.session_id.buf, synth_channel->stop_response->start_line.method_name.buf, synth_channel->stop_response, synth_channel->stop_response->pool);
    return TRUE;
}

/** Callback is called from MPF engine context to read/get new frame */
static apt_bool_t demo_synth_stream_read(mpf_audio_stream_t *stream, mpf_frame_t *frame)
{
    demo_synth_channel_t *synth_channel = stream->obj;
    /* check if STOP was requested */
    if(synth_channel->stop_response) {
        apt_log(APT_LOG_MARK, APT_PRIO_INFO, "Request Stop Response, %s, %s, %0x, %0x", synth_channel->stop_response->channel_id.session_id.buf, synth_channel->stop_response->start_line.method_name.buf, synth_channel->stop_response, synth_channel->stop_response->pool);
......

So the ouput is :

2021-07-20 18:25:20:116614 src/mrcp_server_connection.c:811 140625060026112 [INFO]   Receive MRCPv2 Data 10.233.135.12:1544 <-> 10.233.129.106:37889 [77 bytes]
MRCP/2.0 77 STOP 1454635
Channel-Identifier:38ba5092e94411eb@speechsynth

2021-07-20 18:25:20:116694 src/apt_task.c:264 140625060026112 [INFO]   Signal Message to [MRCP Server] [0x7fe5c40008e0;2;3]
2021-07-20 18:25:20:116755 src/mrcp_server_session.c:575 140625171441408 [INFO]   Dispatch Signaling Message [1]
2021-07-20 18:25:20:116768 src/mrcp_synth_state_machine.c:485 140625171441408 [INFO]   Process STOP Request <38ba5092e94411eb@speechsynth> [1454635]
2021-07-20 18:25:20:116775 src/apt_task.c:264 140625171441408 [INFO]   Signal Message to [Demo Synth Engine] [0x7fe5d4002b30;1;0]
2021-07-20 18:25:20:116835 src/demo_synth_engine.c:352 140625160951552 [INFO]   demo_synth_channel_stop 38ba5092e94411eb, STOP, b40182f8, b4018278

2021-07-20 18:25:20:126218 src/demo_synth_engine.c:499 140625049536256 [INFO]   Request Stop Response, , SPEAK, b40182f8, b4018278
2021-07-20 18:25:20:126240 src/apt_task.c:264 140625049536256 [INFO]   Signal Message to [MRCP Server] [0x7fe5c00008c0;3;4]

It can see the address don't change, but the content of the address is changed, ag : b40182f8, b4018278.

So I guess the memory corrupted, but I can't analysis why.

Would you give me some suggests please?

achaloyan commented 3 years ago

Sorry, I am not able to follow you. Maybe you can use the latest version of UniMRCP such as 1.7.0.

achaloyan commented 2 years ago

Closing this issue for now. If you are able to reproduce the problem with the latest release, please feel free to reopen.