From 129caae5df2d4d698d9ecfb1bf2205e8a4a2b9a2 Mon Sep 17 00:00:00 2001 From: Stefano Di Martino Date: Thu, 8 Aug 2019 22:23:53 +0200 Subject: [PATCH 1/3] Fixing compiler warning: "Counted has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit" This fixed especially a memory leak with a certain gcc version compiled in release mode (no problems in debug mode and with older gcc versions). This could potentially fix #88 and #61. --- src/zxing/zxing/common/Counted.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/zxing/zxing/common/Counted.cpp diff --git a/src/zxing/zxing/common/Counted.cpp b/src/zxing/zxing/common/Counted.cpp new file mode 100644 index 0000000..e69de29 From 52626c6125ef5739c2977ecf0ac715c4449d1d96 Mon Sep 17 00:00:00 2001 From: Stefano Di Martino Date: Thu, 8 Aug 2019 22:26:48 +0200 Subject: [PATCH 2/3] This fixes the compiler warning: "'Counted' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit" This fixes especially memory leaks which we had with a certain gcc version in release mode. This fixes potential #61 and #88 --- src/QZXing.pri | 1 + src/zxing/zxing/common/Counted.cpp | 31 ++++++++++++++++++++++++++++++ src/zxing/zxing/common/Counted.h | 22 ++++++--------------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/QZXing.pri b/src/QZXing.pri index 0d80c0d..08ac77e 100644 --- a/src/QZXing.pri +++ b/src/QZXing.pri @@ -209,6 +209,7 @@ SOURCES += $$PWD/CameraImageWrapper.cpp \ $$PWD/zxing/zxing/WriterException.cpp \ $$PWD/zxing/zxing/aztec/AztecReader.cpp \ $$PWD/zxing/zxing/aztec/AztecDetectorResult.cpp \ + $$PWD/zxing/zxing/common/Counted.cpp \ $$PWD/zxing/zxing/common/StringUtils.cpp \ $$PWD/zxing/zxing/common/Str.cpp \ $$PWD/zxing/zxing/common/PerspectiveTransform.cpp \ diff --git a/src/zxing/zxing/common/Counted.cpp b/src/zxing/zxing/common/Counted.cpp index e69de29..c0f5de0 100644 --- a/src/zxing/zxing/common/Counted.cpp +++ b/src/zxing/zxing/common/Counted.cpp @@ -0,0 +1,31 @@ +#include "Counted.h" + +namespace zxing { + +Counted::~Counted() +{ +} + +Counted *Counted::retain() +{ + count_++; + return this; +} + +void Counted::release() +{ + count_--; + if (count_ == 0) { + count_ = 0xDEADF001; + delete this; + } +} + +int Counted::count() const +{ + return count_; +} + + + +} diff --git a/src/zxing/zxing/common/Counted.h b/src/zxing/zxing/common/Counted.h index a52607c..2ccd7f7 100644 --- a/src/zxing/zxing/common/Counted.h +++ b/src/zxing/zxing/common/Counted.h @@ -30,25 +30,15 @@ public: Counted() : count_(0) { } - virtual ~Counted() { - } - Counted *retain() { - count_++; - return this; - } - void release() { - count_--; - if (count_ == 0) { - count_ = 0xDEADF001; - delete this; - } - } + virtual ~Counted(); + + Counted *retain(); + + void release(); /* return the current count for denugging purposes or similar */ - int count() const { - return count_; - } + int count() const; }; /* counting reference to reference-counted objects */ From 65085a7bb150226a03679f8d9404bf464e291daf Mon Sep 17 00:00:00 2001 From: Stefano Di Martino Date: Fri, 9 Aug 2019 07:55:45 +0200 Subject: [PATCH 3/3] Move constructor implemenation to cpp --- src/zxing/zxing/common/Counted.cpp | 5 +++++ src/zxing/zxing/common/Counted.h | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/zxing/zxing/common/Counted.cpp b/src/zxing/zxing/common/Counted.cpp index c0f5de0..a80807f 100644 --- a/src/zxing/zxing/common/Counted.cpp +++ b/src/zxing/zxing/common/Counted.cpp @@ -2,6 +2,11 @@ namespace zxing { +Counted::Counted() : + count_(0) +{ +} + Counted::~Counted() { } diff --git a/src/zxing/zxing/common/Counted.h b/src/zxing/zxing/common/Counted.h index 2ccd7f7..bcf4b17 100644 --- a/src/zxing/zxing/common/Counted.h +++ b/src/zxing/zxing/common/Counted.h @@ -27,9 +27,7 @@ class Counted { private: unsigned int count_; public: - Counted() : - count_(0) { - } + Counted(); virtual ~Counted();