Skip to content

The cmark_markdown_to_html function call uses free to release crashes #577

@aloneisbestes

Description

@aloneisbestes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions