Skip to content

Commit

Permalink
Merge pull request #1594 from Waqar144/fix-mem
Browse files Browse the repository at this point in the history
Fix memory leak in preview
  • Loading branch information
pbek committed Jan 18, 2020
2 parents e159215 + 88dfc6e commit 295c587
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/entities/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2085,16 +2085,13 @@ QString Note::textToMarkdownHtml(QString str, const QString& notesPath,
highlightCode(str, QStringLiteral("```"), cbCount);
highlightCode(str, QStringLiteral("~~~"), cbTildeCount);

const char *data = qstrdup(str.toUtf8().constData());
size_t length = strlen(data);

// return an empty string if the note is empty
if (length == 0) {
auto data = str.toUtf8();
if (data.size() == 0) {
return QLatin1String("");
}

QByteArray array;
int renderResult = md_render_html(data, MD_SIZE(length),
int renderResult = md_render_html(data.data(), MD_SIZE(data.size()),
&captureHtmlFragment,
&array,
flags,
Expand All @@ -2105,6 +2102,7 @@ QString Note::textToMarkdownHtml(QString str, const QString& notesPath,
result = QString::fromUtf8(array);
} else {
qWarning() << "MD4C Failure!";
return QString();
}

// transform remote preview image tags
Expand Down

0 comments on commit 295c587

Please sign in to comment.