[Libwebsockets] Segfault after doing lws_ring_insert

prelag at yahoo.com prelag at yahoo.com
Wed Aug 5 20:37:57 CEST 2020


Thanks in advance!  I know this is something simple I am overlooking.

I have a test program based on the client echo example.  I am attempting to create a message and insert it into the ring_buffer to get picked up on the next LWS_CALLBACK_CLIENT_WRITEABLE.

Here is my simple function that is called when a message is ready to be put in the buffer:

void MyClass::sendResponse(string &response) {
    syslog(LOG_DEBUG, "MyClass::sendResponse %s", response.c_str());

    int len = strlen(response.c_str() + LWS_PRE);

    msg3.payload = malloc(len);

    memcpy((char *) msg3.payload + LWS_PRE, response.c_str(), len);
    msg3.len = len;

    //lws_ring_insert(pss->ring, &msg3, 1);

    if (!lws_ring_insert(pss->ring, &msg3, 1)) {  //<--- directly after the ring_insert we get a segfault

        syslog(LOG_DEBUG, "dropping!\n");


struct msg is:

/* one of these created for each message */
struct msg {
    void *payload; /* is malloc'd */
    size_t len;
    char binary;
    char first;
    char final;

Here is the stack trace:

_Unwind_VRS_Pop() at unwind-arm.c:240 0xb6c724f0    
__gnu_unwind_execute() at pr-support.c:153 0xb6c72b18    
__gnu_unwind_frame() at pr-support.c:331 0xb6c72db8    
__cxxabiv1::__gxx_personality_v0() at eh_personality.cc:386 0xb6bc788c    
__gnu_Unwind_Backtrace() at unwind-arm-common.inc:589 0xb6c7206c    
___Unwind_Backtrace() at libunwind.S:360 0xb6c72984    
__GI___backtrace() at backtrace.c:105 0xb6d61a14    
backtrace_and_maps() at libc_fatal.c:47 0xb6c9a054    
__libc_message() at libc_fatal.c:172 0xb6ce9c04    
malloc_printerr() at malloc.c:5,046 0xb6cf0724    
_int_malloc() at malloc.c:3,509 0xb6cf2a58    
__GI___libc_malloc() at malloc.c:2,925 0xb6cf4d2c    
__GI___open_memstream() at memstream.c:76 0xb6ce82cc    
__GI___vsyslog_chk() at syslog.c:167 0xb6d4fb64    
__syslog() at syslog.c:117 0xb6d50120    
lwsl_emit_syslog() at unix-misc.c:80 0xb6f33bae    
_lws_logv() at logs.c:188 0xb6f12c6a    
_lws_log() at logs.c:196 0xb6f12cb6    
_lws_change_pollfd() at pollfd.c:150 0xb6f17048    
__lws_change_pollfd() at pollfd.c:479 0xb6f17770    
lws_change_pollfd() at pollfd.c:500 0xb6f177b0    
lws_handle_POLLOUT_event() at service.c:168 0xb6f17cec    
rops_handle_POLLIN_ws() at ops-ws.c:993 0xb6f2087e    
lws_service_fd_tsi() at service.c:703 0xb6f186c6    
_lws_plat_service_forced_tsi() at unix-service.c:49 0xb6f343ba    
_lws_plat_service_tsi() at unix-service.c:207 0xb6f34774    
lws_plat_service() at unix-service.c:221 0xb6f347cc    
lws_service() at service.c:770 0xb6f1880a    


Paul Roberts

More information about the Libwebsockets mailing list