From 43acdace32d5d2d16f1a9e70edaf1ab93148d973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Wed, 12 Jun 2019 23:28:01 +0200 Subject: [PATCH 1/4] Fixed Memory leak in BackgroundImage #1198 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved impl of BackgroundImageContents into the BackgroundImage source file to reduce code bloat and increase encapsulation. Removed unessesary header and source BackgroundImageContents. Replaced custom memory management with a std::shared_ptr. Refactored BackgroundImage. Signed-off-by: Fabian Keßler --- src/model/BackgroundImage.cpp | 150 +++++++++++--------------- src/model/BackgroundImage.h | 10 +- src/model/BackgroundImageContents.cpp | 94 ---------------- src/model/BackgroundImageContents.h | 64 ----------- 4 files changed, 69 insertions(+), 249 deletions(-) delete mode 100644 src/model/BackgroundImageContents.cpp delete mode 100644 src/model/BackgroundImageContents.h diff --git a/src/model/BackgroundImage.cpp b/src/model/BackgroundImage.cpp index 9eb02f2f..21781ebf 100644 --- a/src/model/BackgroundImage.cpp +++ b/src/model/BackgroundImage.cpp @@ -1,185 +1,161 @@ #include "BackgroundImage.h" -#include "BackgroundImageContents.h" -#include +#include "Stacktrace.h" + +/* + * Xournal++ + * + * The contents of a background image + * Internal impl object, dont move this to an external header/source file due this is the best way to reduce code + * bloat and increase encapsulation. This object is only used in this source and is a RAII Container for the GdkPixbuf* + * No xournal memory leak tests necessary, because we use smart ptrs to ensure memory correctness + * + * @author Xournal++ Team + * https://github.com/xournalpp/xournalpp + * + * @license GNU GPLv2 or later + * + */ + +struct BackgroundImageContents +{ + BackgroundImageContents(string filename, GError** error) + : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_file(this->filename.c_str(), error)) + {} + BackgroundImageContents(GInputStream* stream, string filename, GError** error) + : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_stream(stream, nullptr, error)) + {} + + BackgroundImageContents(const BackgroundImageContents&) = delete; + BackgroundImageContents(BackgroundImageContents&&) = default; + BackgroundImageContents& operator=(const BackgroundImageContents&) = delete; + BackgroundImageContents& operator=(BackgroundImageContents&&) = default; + + ~BackgroundImageContents() + { + g_object_unref(this->pixbuf); + this->pixbuf = nullptr; + }; + string filename; + + GdkPixbuf* pixbuf = nullptr; + + int pageId = -1; + bool attach = false; +}; BackgroundImage::BackgroundImage() { XOJ_INIT_TYPE(BackgroundImage); } -BackgroundImage::BackgroundImage(const BackgroundImage& img) +BackgroundImage::BackgroundImage(const BackgroundImage& img) : img(img.img) { XOJ_INIT_TYPE(BackgroundImage); XOJ_CHECK_TYPE_OBJ((&img), BackgroundImage); +} - this->img = img.img; - if (this->img) - { - this->img->reference(); - } +BackgroundImage::BackgroundImage(BackgroundImage&& img) noexcept : img(std::move(img.img)) +{ + XOJ_INIT_TYPE(BackgroundImage); + XOJ_CHECK_TYPE_OBJ((&img), BackgroundImage); } BackgroundImage::~BackgroundImage() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - this->img->unreference(); - } - this->img = NULL; - XOJ_RELEASE_TYPE(BackgroundImage); } string BackgroundImage::getFilename() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img != NULL) - { - return this->img->getFilename(); - } - return ""; + return this->img ? this->img->filename : ""; } void BackgroundImage::loadFile(string filename, GError** error) { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img != NULL) - { - this->img->unreference(); - } - this->img = new BackgroundImageContents(filename, error); + this->img = std::make_shared(std::move(filename), error); } void BackgroundImage::loadFile(GInputStream* stream, string filename, GError** error) { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img != NULL) - { - this->img->unreference(); - } - this->img = new BackgroundImageContents(stream, filename, error); + this->img = std::make_shared(stream, std::move(filename), error); } void BackgroundImage::setAttach(bool attach) { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img != NULL) - { - this->img->setAttach(true); - } - else + if (!this->img) { g_warning("BackgroundImage::setAttach:please load first an image before call setAttach!"); Stacktrace::printStracktrace(); + return; } -} - -void BackgroundImage::operator=(BackgroundImage& img) -{ - XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - this->img->unreference(); - } - this->img = img.img; - if (this->img) - { - this->img->reference(); - } + this->img->attach = attach; } bool BackgroundImage::operator==(const BackgroundImage& img) { XOJ_CHECK_TYPE(BackgroundImage); - return this->img == img.img; } void BackgroundImage::free() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - this->img->unreference(); - } - this->img = NULL; + this->img.reset(); } void BackgroundImage::clearSaveState() { XOJ_CHECK_TYPE(BackgroundImage); - if (this->img) { - this->img->setPageId(-1); + this->img->pageId = -1; } } int BackgroundImage::getCloneId() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - return this->img->getPageId(); - } - return -1; + return this->img? this->img->pageId : -1; } void BackgroundImage::setCloneId(int id) { XOJ_CHECK_TYPE(BackgroundImage); - if (this->img) { - this->img->setPageId(id); + this->img->pageId = id; } } void BackgroundImage::setFilename(string filename) { XOJ_CHECK_TYPE(BackgroundImage); - if (this->img) { - this->img->setFilename(filename); + this->img->filename = std::move(filename); } } bool BackgroundImage::isAttached() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - return this->img->isAttach(); - } - return false; + return this->img ? this->img->attach: false; } bool BackgroundImage::isEmpty() { XOJ_CHECK_TYPE(BackgroundImage); - - return this->img == NULL; + return !this->img; } GdkPixbuf* BackgroundImage::getPixbuf() { XOJ_CHECK_TYPE(BackgroundImage); - - if (this->img) - { - return this->img->getPixbuf(); - } - return NULL; + return this->img ? this->img->pixbuf: nullptr; } diff --git a/src/model/BackgroundImage.h b/src/model/BackgroundImage.h index 08e543a2..521a339e 100644 --- a/src/model/BackgroundImage.h +++ b/src/model/BackgroundImage.h @@ -22,16 +22,19 @@ class BackgroundImage public: BackgroundImage(); BackgroundImage(const BackgroundImage& img); + BackgroundImage(BackgroundImage&& img) noexcept; virtual ~BackgroundImage(); + BackgroundImage& operator=(const BackgroundImage& img) = default; + BackgroundImage& operator=(BackgroundImage&& img) = default; + public: string getFilename(); void loadFile(string filename, GError** error); + void loadFile(GInputStream* stream, string filename, GError** error); void setAttach(bool attach); - - void operator=(BackgroundImage& img); bool operator==(const BackgroundImage& img); void free(); @@ -49,6 +52,5 @@ public: private: XOJ_TYPE_ATTRIB; - - BackgroundImageContents* img = NULL; + std::shared_ptr img; }; diff --git a/src/model/BackgroundImageContents.cpp b/src/model/BackgroundImageContents.cpp deleted file mode 100644 index 7ed58dc9..00000000 --- a/src/model/BackgroundImageContents.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "BackgroundImageContents.h" - -BackgroundImageContents::BackgroundImageContents(string filename, GError** error) -{ - XOJ_INIT_TYPE(BackgroundImageContents); - - this->filename = filename; - this->pixbuf = gdk_pixbuf_new_from_file(filename.c_str(), error); -} - -BackgroundImageContents::BackgroundImageContents(GInputStream* stream, string filename, GError** error) -{ - XOJ_INIT_TYPE(BackgroundImageContents); - - this->filename = filename; - this->pixbuf = gdk_pixbuf_new_from_stream(stream, nullptr, error); -} - -BackgroundImageContents::~BackgroundImageContents() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - g_object_unref(this->pixbuf); - this->pixbuf = NULL; - - XOJ_RELEASE_TYPE(BackgroundImageContents); -} - -void BackgroundImageContents::unreference() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - this->ref--; - if (this->ref < 0) - { - delete this; - } -} - -void BackgroundImageContents::reference() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - this->ref++; -} - -string BackgroundImageContents::getFilename() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - return this->filename; -} - -void BackgroundImageContents::setFilename(string filename) -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - this->filename = filename; -} - -bool BackgroundImageContents::isAttach() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - return this->attach; -} - -void BackgroundImageContents::setAttach(bool attach) -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - this->attach = attach; -} - -int BackgroundImageContents::getPageId() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - return this->pageId; -} - -void BackgroundImageContents::setPageId(int id) -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - this->pageId = id; -} - -GdkPixbuf* BackgroundImageContents::getPixbuf() -{ - XOJ_CHECK_TYPE(BackgroundImageContents); - - return this->pixbuf; -} diff --git a/src/model/BackgroundImageContents.h b/src/model/BackgroundImageContents.h deleted file mode 100644 index 450d6eca..00000000 --- a/src/model/BackgroundImageContents.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Xournal++ - * - * The contents of a background image - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - */ - -#pragma once - -#include - -#include - -class BackgroundImageContents -{ -public: - BackgroundImageContents(string filename, GError** error); - BackgroundImageContents(GInputStream* stream, string filename, GError** error); - -private: - BackgroundImageContents(); - BackgroundImageContents(const BackgroundImageContents& contents); - void operator=(const BackgroundImageContents& contents); - -private: - virtual ~BackgroundImageContents(); - -public: - void unreference(); - void reference(); - -public: - string getFilename(); - void setFilename(string filename); - - bool isAttach(); - void setAttach(bool attach); - - int getPageId(); - void setPageId(int id); - - GdkPixbuf* getPixbuf(); - -private: - XOJ_TYPE_ATTRIB; - - /** - * Reference counter - */ - int ref = 1; - - string filename; - bool attach = false; - - /** - * - */ - int pageId = -1; - GdkPixbuf* pixbuf = NULL; -}; From e619a893260ed78e4fe2b3e076813a529969fef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Thu, 13 Jun 2019 02:00:19 +0200 Subject: [PATCH 2/4] BackgroundImage: - reformat and reordered the code, - added include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Keßler --- src/model/BackgroundImage.cpp | 92 ++++++++++++++++------------------- src/model/BackgroundImage.h | 29 +++++------ 2 files changed, 56 insertions(+), 65 deletions(-) diff --git a/src/model/BackgroundImage.cpp b/src/model/BackgroundImage.cpp index 21781ebf..7a8d8574 100644 --- a/src/model/BackgroundImage.cpp +++ b/src/model/BackgroundImage.cpp @@ -3,43 +3,37 @@ #include "Stacktrace.h" /* - * Xournal++ - * * The contents of a background image + * * Internal impl object, dont move this to an external header/source file due this is the best way to reduce code - * bloat and increase encapsulation. This object is only used in this source and is a RAII Container for the GdkPixbuf* + * bloat and increase encapsulation. This object is only used in this source scope and is a RAII Container for the + * GdkPixbuf* * No xournal memory leak tests necessary, because we use smart ptrs to ensure memory correctness - * - * @author Xournal++ Team - * https://github.com/xournalpp/xournalpp - * - * @license GNU GPLv2 or later - * */ struct BackgroundImageContents { BackgroundImageContents(string filename, GError** error) - : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_file(this->filename.c_str(), error)) + : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_file(this->filename.c_str(), error)) {} + BackgroundImageContents(GInputStream* stream, string filename, GError** error) - : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_stream(stream, nullptr, error)) + : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_stream(stream, nullptr, error)) {} - BackgroundImageContents(const BackgroundImageContents&) = delete; - BackgroundImageContents(BackgroundImageContents&&) = default; - BackgroundImageContents& operator=(const BackgroundImageContents&) = delete; - BackgroundImageContents& operator=(BackgroundImageContents&&) = default; - ~BackgroundImageContents() { g_object_unref(this->pixbuf); this->pixbuf = nullptr; }; - string filename; - GdkPixbuf* pixbuf = nullptr; + BackgroundImageContents(const BackgroundImageContents&) = delete; + BackgroundImageContents(BackgroundImageContents&&) = default; + BackgroundImageContents& operator=(const BackgroundImageContents&) = delete; + BackgroundImageContents& operator=(BackgroundImageContents&&) = default; + string filename; + GdkPixbuf* pixbuf = nullptr; int pageId = -1; bool attach = false; }; @@ -67,10 +61,10 @@ BackgroundImage::~BackgroundImage() XOJ_RELEASE_TYPE(BackgroundImage); } -string BackgroundImage::getFilename() +bool BackgroundImage::operator==(const BackgroundImage& img) { XOJ_CHECK_TYPE(BackgroundImage); - return this->img ? this->img->filename : ""; + return this->img == img.img; } void BackgroundImage::loadFile(string filename, GError** error) @@ -85,67 +79,63 @@ void BackgroundImage::loadFile(GInputStream* stream, string filename, GError** e this->img = std::make_shared(stream, std::move(filename), error); } -void BackgroundImage::setAttach(bool attach) +int BackgroundImage::getCloneId() { XOJ_CHECK_TYPE(BackgroundImage); - if (!this->img) + return this->img? this->img->pageId: -1; +} + +void BackgroundImage::setCloneId(int id) +{ + XOJ_CHECK_TYPE(BackgroundImage); + if (this->img) { - g_warning("BackgroundImage::setAttach:please load first an image before call setAttach!"); - Stacktrace::printStracktrace(); - return; + this->img->pageId = id; } - this->img->attach = attach; } -bool BackgroundImage::operator==(const BackgroundImage& img) +void BackgroundImage::clearSaveState() { - XOJ_CHECK_TYPE(BackgroundImage); - return this->img == img.img; + this->setCloneId(-1); } -void BackgroundImage::free() +string BackgroundImage::getFilename() { XOJ_CHECK_TYPE(BackgroundImage); - this->img.reset(); + return this->img? this->img->filename: ""; } -void BackgroundImage::clearSaveState() +void BackgroundImage::setFilename(string filename) { XOJ_CHECK_TYPE(BackgroundImage); if (this->img) { - this->img->pageId = -1; + this->img->filename = std::move(filename); } } -int BackgroundImage::getCloneId() -{ - XOJ_CHECK_TYPE(BackgroundImage); - return this->img? this->img->pageId : -1; -} - -void BackgroundImage::setCloneId(int id) +bool BackgroundImage::isAttached() { XOJ_CHECK_TYPE(BackgroundImage); - if (this->img) - { - this->img->pageId = id; - } + return this->img? this->img->attach: false; } -void BackgroundImage::setFilename(string filename) +void BackgroundImage::setAttach(bool attach) { XOJ_CHECK_TYPE(BackgroundImage); - if (this->img) + if (!this->img) { - this->img->filename = std::move(filename); + g_warning("BackgroundImage::setAttach: please load first an image before call setAttach!"); + Stacktrace::printStracktrace(); + return; } + this->img->attach = attach; } -bool BackgroundImage::isAttached() +GdkPixbuf* BackgroundImage::getPixbuf() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img ? this->img->attach: false; + return this->img? this->img->pixbuf: nullptr; } bool BackgroundImage::isEmpty() @@ -154,8 +144,8 @@ bool BackgroundImage::isEmpty() return !this->img; } -GdkPixbuf* BackgroundImage::getPixbuf() +void BackgroundImage::free() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img ? this->img->pixbuf: nullptr; + this->img.reset(); } diff --git a/src/model/BackgroundImage.h b/src/model/BackgroundImage.h index 521a339e..e4549cba 100644 --- a/src/model/BackgroundImage.h +++ b/src/model/BackgroundImage.h @@ -11,45 +11,46 @@ #pragma once -#include +#include "XournalType.h" #include -class BackgroundImageContents; +#include -class BackgroundImage +struct BackgroundImageContents; + +struct BackgroundImage { -public: BackgroundImage(); BackgroundImage(const BackgroundImage& img); BackgroundImage(BackgroundImage&& img) noexcept; - virtual ~BackgroundImage(); + ~BackgroundImage(); BackgroundImage& operator=(const BackgroundImage& img) = default; BackgroundImage& operator=(BackgroundImage&& img) = default; -public: - string getFilename(); - void loadFile(string filename, GError** error); - - void loadFile(GInputStream* stream, string filename, GError** error); - void setAttach(bool attach); bool operator==(const BackgroundImage& img); - void free(); + void loadFile(string filename, GError** error); + void loadFile(GInputStream* stream, string filename, GError** error); - void clearSaveState(); int getCloneId(); void setCloneId(int id); + void clearSaveState(); + string getFilename(); void setFilename(string filename); bool isAttached(); - bool isEmpty(); + void setAttach(bool attach); GdkPixbuf* getPixbuf(); + bool isEmpty(); + + void free(); + private: XOJ_TYPE_ATTRIB; std::shared_ptr img; From 935f376fe18f9f6bbfc7f9d1f97dca1b4f11b527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Thu, 13 Jun 2019 02:20:04 +0200 Subject: [PATCH 3/4] BackgroundImage: - reformat and reordered the code, - added include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Keßler --- src/model/BackgroundImage.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/model/BackgroundImage.cpp b/src/model/BackgroundImage.cpp index 7a8d8574..20d57d30 100644 --- a/src/model/BackgroundImage.cpp +++ b/src/model/BackgroundImage.cpp @@ -15,11 +15,13 @@ struct BackgroundImageContents { BackgroundImageContents(string filename, GError** error) : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_file(this->filename.c_str(), error)) - {} + { + } BackgroundImageContents(GInputStream* stream, string filename, GError** error) : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_stream(stream, nullptr, error)) - {} + { + } ~BackgroundImageContents() { @@ -82,7 +84,7 @@ void BackgroundImage::loadFile(GInputStream* stream, string filename, GError** e int BackgroundImage::getCloneId() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img? this->img->pageId: -1; + return this->img ? this->img->pageId : -1; } void BackgroundImage::setCloneId(int id) @@ -102,7 +104,7 @@ void BackgroundImage::clearSaveState() string BackgroundImage::getFilename() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img? this->img->filename: ""; + return this->img ? this->img->filename : ""; } void BackgroundImage::setFilename(string filename) @@ -117,7 +119,7 @@ void BackgroundImage::setFilename(string filename) bool BackgroundImage::isAttached() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img? this->img->attach: false; + return this->img ? this->img->attach : false; } void BackgroundImage::setAttach(bool attach) @@ -135,7 +137,7 @@ void BackgroundImage::setAttach(bool attach) GdkPixbuf* BackgroundImage::getPixbuf() { XOJ_CHECK_TYPE(BackgroundImage); - return this->img? this->img->pixbuf: nullptr; + return this->img ? this->img->pixbuf : nullptr; } bool BackgroundImage::isEmpty() From bd318bdc5a4336512478331c39948fb434bee51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ke=C3=9Fler?= Date: Thu, 13 Jun 2019 07:44:37 +0200 Subject: [PATCH 4/4] =?UTF-8?q?Applied=20@Technius=20feedback=20moved=20th?= =?UTF-8?q?e=20forward=20declaration=20of=20BackgroundImageContents=20into?= =?UTF-8?q?=20a=20=C3=9Fprivate=20section=20of=20BackgroundImage=20and=20r?= =?UTF-8?q?enamed=20it=20to=20Content?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Keßler --- src/model/BackgroundImage.cpp | 32 ++++++++++++++++---------------- src/model/BackgroundImage.h | 10 +++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/model/BackgroundImage.cpp b/src/model/BackgroundImage.cpp index 20d57d30..0aff32b6 100644 --- a/src/model/BackgroundImage.cpp +++ b/src/model/BackgroundImage.cpp @@ -11,28 +11,28 @@ * No xournal memory leak tests necessary, because we use smart ptrs to ensure memory correctness */ -struct BackgroundImageContents +struct BackgroundImage::Content { - BackgroundImageContents(string filename, GError** error) + Content(string filename, GError** error) : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_file(this->filename.c_str(), error)) { } - BackgroundImageContents(GInputStream* stream, string filename, GError** error) + Content(GInputStream* stream, string filename, GError** error) : filename(std::move(filename)), pixbuf(gdk_pixbuf_new_from_stream(stream, nullptr, error)) { } - ~BackgroundImageContents() + ~Content() { g_object_unref(this->pixbuf); this->pixbuf = nullptr; }; - BackgroundImageContents(const BackgroundImageContents&) = delete; - BackgroundImageContents(BackgroundImageContents&&) = default; - BackgroundImageContents& operator=(const BackgroundImageContents&) = delete; - BackgroundImageContents& operator=(BackgroundImageContents&&) = default; + Content(const Content&) = delete; + Content(Content&&) = default; + Content& operator=(const Content&) = delete; + Content& operator=(Content&&) = default; string filename; GdkPixbuf* pixbuf = nullptr; @@ -69,16 +69,22 @@ bool BackgroundImage::operator==(const BackgroundImage& img) return this->img == img.img; } +void BackgroundImage::free() +{ + XOJ_CHECK_TYPE(BackgroundImage); + this->img.reset(); +} + void BackgroundImage::loadFile(string filename, GError** error) { XOJ_CHECK_TYPE(BackgroundImage); - this->img = std::make_shared(std::move(filename), error); + this->img = std::make_shared(std::move(filename), error); } void BackgroundImage::loadFile(GInputStream* stream, string filename, GError** error) { XOJ_CHECK_TYPE(BackgroundImage); - this->img = std::make_shared(stream, std::move(filename), error); + this->img = std::make_shared(stream, std::move(filename), error); } int BackgroundImage::getCloneId() @@ -145,9 +151,3 @@ bool BackgroundImage::isEmpty() XOJ_CHECK_TYPE(BackgroundImage); return !this->img; } - -void BackgroundImage::free() -{ - XOJ_CHECK_TYPE(BackgroundImage); - this->img.reset(); -} diff --git a/src/model/BackgroundImage.h b/src/model/BackgroundImage.h index e4549cba..660589c5 100644 --- a/src/model/BackgroundImage.h +++ b/src/model/BackgroundImage.h @@ -17,8 +17,6 @@ #include -struct BackgroundImageContents; - struct BackgroundImage { BackgroundImage(); @@ -32,6 +30,8 @@ struct BackgroundImage bool operator==(const BackgroundImage& img); + void free(); + void loadFile(string filename, GError** error); void loadFile(GInputStream* stream, string filename, GError** error); @@ -49,9 +49,9 @@ struct BackgroundImage bool isEmpty(); - void free(); - private: + struct Content; + XOJ_TYPE_ATTRIB; - std::shared_ptr img; + std::shared_ptr img; };