glib/poppler-annot.cc | 10 ++-------- poppler/Annot.cc | 16 ++++++++-------- poppler/Annot.h | 8 ++++---- qt5/src/poppler-annotation.cc | 8 ++------ qt6/src/poppler-annotation.cc | 8 ++------ 5 files changed, 18 insertions(+), 32 deletions(-)
New commits: commit 26fb316af4dcfb5d909b44e63fd7991f16e11d0a Author: Albert Astals Cid <aa...@kde.org> Date: Tue Mar 1 17:44:00 2022 +0100 AnnotMarkup::setLabel: Take a unique_ptr This was double deleting on the glib side diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index dbc7e5fa..a8bbd76f 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -1020,7 +1020,6 @@ gchar *poppler_annot_markup_get_label(PopplerAnnotMarkup *poppler_annot) void poppler_annot_markup_set_label(PopplerAnnotMarkup *poppler_annot, const gchar *label) { AnnotMarkup *annot; - GooString *goo_tmp; gchar *tmp; gsize length = 0; @@ -1029,10 +1028,8 @@ void poppler_annot_markup_set_label(PopplerAnnotMarkup *poppler_annot, const gch annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT(poppler_annot)->annot); tmp = label ? g_convert(label, -1, "UTF-16BE", "UTF-8", nullptr, &length, nullptr) : nullptr; - goo_tmp = new GooString(tmp, length); + annot->setLabel(std::make_unique<GooString>(tmp, length)); g_free(tmp); - annot->setLabel(goo_tmp); - delete goo_tmp; } /** diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 30d65b39..7f9bfbbc 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -2184,10 +2184,10 @@ void AnnotMarkup::initialize(PDFDoc *docA, Dict *dict) } } -void AnnotMarkup::setLabel(GooString *new_label) +void AnnotMarkup::setLabel(std::unique_ptr<GooString> &&new_label) { if (new_label) { - label = std::make_unique<GooString>(new_label); + label = std::move(new_label); // append the unicode marker <FE FF> if needed if (!label->hasUnicodeMarker()) { label->prependUnicodeMarker(); diff --git a/poppler/Annot.h b/poppler/Annot.h index 4220b36c..7bc08d4f 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -866,7 +866,7 @@ public: // The annotation takes the ownership of new_popup void setPopup(std::unique_ptr<AnnotPopup> &&new_popup); - void setLabel(GooString *new_label); + void setLabel(std::unique_ptr<GooString> &&new_label); void setOpacity(double opacityA); void setDate(GooString *new_date); diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc index fdc45c31..cca9737b 100644 --- a/qt5/src/poppler-annotation.cc +++ b/qt5/src/poppler-annotation.cc @@ -1361,9 +1361,7 @@ void Annotation::setAuthor(const QString &author) AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); if (markupann) { - GooString *s = QStringToUnicodeGooString(author); - markupann->setLabel(s); - delete s; + markupann->setLabel(std::unique_ptr<GooString>(QStringToUnicodeGooString(author))); } } diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc index 53cc7456..43408bf3 100644 --- a/qt6/src/poppler-annotation.cc +++ b/qt6/src/poppler-annotation.cc @@ -1024,9 +1024,7 @@ void Annotation::setAuthor(const QString &author) AnnotMarkup *markupann = dynamic_cast<AnnotMarkup *>(d->pdfAnnot); if (markupann) { - GooString *s = QStringToUnicodeGooString(author); - markupann->setLabel(s); - delete s; + markupann->setLabel(std::unique_ptr<GooString>(QStringToUnicodeGooString(author))); } } commit bd24fb667c0deb220aa7e05cbf2b1807b57fff9b Author: Albert Astals Cid <aa...@kde.org> Date: Tue Mar 1 17:41:29 2022 +0100 Annot::setContents: Take a unique_ptr This was double deleting on the glib side diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index 53205658..dbc7e5fa 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -700,17 +700,14 @@ gchar *poppler_annot_get_contents(PopplerAnnot *poppler_annot) **/ void poppler_annot_set_contents(PopplerAnnot *poppler_annot, const gchar *contents) { - GooString *goo_tmp; gchar *tmp; gsize length = 0; g_return_if_fail(POPPLER_IS_ANNOT(poppler_annot)); tmp = contents ? g_convert(contents, -1, "UTF-16BE", "UTF-8", nullptr, &length, nullptr) : nullptr; - goo_tmp = new GooString(tmp, length); + poppler_annot->annot->setContents(std::make_unique<GooString>(tmp, length)); g_free(tmp); - poppler_annot->annot->setContents(goo_tmp); - delete (goo_tmp); } /** diff --git a/poppler/Annot.cc b/poppler/Annot.cc index 9d170784..30d65b39 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -1484,12 +1484,12 @@ void Annot::update(const char *key, Object &&value) doc->getXRef()->setModifiedObject(&annotObj, ref); } -void Annot::setContents(GooString *new_content) +void Annot::setContents(std::unique_ptr<GooString> &&new_content) { annotLocker(); if (new_content) { - contents = std::make_unique<GooString>(new_content); + contents = std::move(new_content); // append the unicode marker <FE FF> if needed if (!contents->hasUnicodeMarker()) { contents->prependUnicodeMarker(); @@ -2884,9 +2884,9 @@ void AnnotFreeText::initialize(PDFDoc *docA, Dict *dict) } } -void AnnotFreeText::setContents(GooString *new_content) +void AnnotFreeText::setContents(std::unique_ptr<GooString> &&new_content) { - Annot::setContents(new_content); + Annot::setContents(std::move(new_content)); invalidateAppearance(); } @@ -3279,9 +3279,9 @@ void AnnotLine::initialize(PDFDoc *docA, Dict *dict) } } -void AnnotLine::setContents(GooString *new_content) +void AnnotLine::setContents(std::unique_ptr<GooString> &&new_content) { - Annot::setContents(new_content); + Annot::setContents(std::move(new_content)); if (caption) invalidateAppearance(); } diff --git a/poppler/Annot.h b/poppler/Annot.h index b7a34bb3..4220b36c 100644 --- a/poppler/Annot.h +++ b/poppler/Annot.h @@ -719,7 +719,7 @@ public: // Sets the annot contents to new_content // new_content should never be NULL - virtual void setContents(GooString *new_content); + virtual void setContents(std::unique_ptr<GooString> &&new_content); void setName(GooString *new_name); void setModified(GooString *new_modified); void setFlags(unsigned int new_flags); @@ -1051,7 +1051,7 @@ public: void draw(Gfx *gfx, bool printing) override; Object getAppearanceResDict() override; - void setContents(GooString *new_content) override; + void setContents(std::unique_ptr<GooString> &&new_content) override; void setDefaultAppearance(const DefaultAppearance &da); void setQuadding(AnnotFreeTextQuadding new_quadding); @@ -1115,7 +1115,7 @@ public: void draw(Gfx *gfx, bool printing) override; Object getAppearanceResDict() override; - void setContents(GooString *new_content) override; + void setContents(std::unique_ptr<GooString> &&new_content) override; void setVertices(double x1, double y1, double x2, double y2); void setStartEndStyle(AnnotLineEndingStyle start, AnnotLineEndingStyle end); diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc index 20a4a534..fdc45c31 100644 --- a/qt5/src/poppler-annotation.cc +++ b/qt5/src/poppler-annotation.cc @@ -1386,9 +1386,7 @@ void Annotation::setContents(const QString &contents) return; } - GooString *s = QStringToUnicodeGooString(contents); - d->pdfAnnot->setContents(s); - delete s; + d->pdfAnnot->setContents(std::unique_ptr<GooString>(QStringToUnicodeGooString(contents))); } QString Annotation::uniqueName() const diff --git a/qt6/src/poppler-annotation.cc b/qt6/src/poppler-annotation.cc index 748749cd..53cc7456 100644 --- a/qt6/src/poppler-annotation.cc +++ b/qt6/src/poppler-annotation.cc @@ -1049,9 +1049,7 @@ void Annotation::setContents(const QString &contents) return; } - GooString *s = QStringToUnicodeGooString(contents); - d->pdfAnnot->setContents(s); - delete s; + d->pdfAnnot->setContents(std::unique_ptr<GooString>(QStringToUnicodeGooString(contents))); } QString Annotation::uniqueName() const