[Libwebsockets] Segfault after doing lws_ring_insert

Andy Green andy at warmcat.com
Wed Aug 5 20:48:42 CEST 2020



On 8/5/20 7:37 PM, prelag at yahoo.com wrote:
> Hello,
> 
> 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);

You're writing beyond what you allocated-->

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

None of that is any lws issue.

-Andy


More information about the Libwebsockets mailing list