cmark icon indicating copy to clipboard operation
cmark copied to clipboard

The cmark_markdown_to_html function call uses free to release crashes

Open aloneisbestes opened this issue 8 months ago • 2 comments

QString DeepSeekWidgetUI::convertMarkdownToHtml(const QString& markdown) { QByteArray byteArray = markdown.toUtf8(); const char* markdownCString = byteArray.constData();

char* html = cmark_markdown_to_html(markdownCString, strlen(markdownCString), CMARK_OPT_DEFAULT);
if (html == NULL)
{
	return markdown;
}

QString htmlText = QString::fromUtf8(html);

free(html);

return htmlText;

}

After calling the cmark_markdown_to_html function, I copied the data to the QString, then released the memory and crashed directly. I thought it was a problem with the QString::fromUtf8() function, so I tested it and executed free() before QString::fromUtf8(), and it crashed as well.

This is the result of the call after QString::fromUtf8() Image

This is the result of the call before QString::fromUtf8()

Image

aloneisbestes avatar Apr 29 '25 02:04 aloneisbestes

I also had this problem. I had thought there's no need to call free().

pigrich avatar Sep 06 '25 14:09 pigrich

You need to use cmark_node_free I think.

jgm avatar Sep 06 '25 16:09 jgm