Skip to content

Commit cd11aa5

Browse files
authored
Merge pull request #808 from datapathltd/datapath_asan_alloc_mismatch_fix
Fix to ensure the custom deallocator for zint_symbol is used for std::shared_ptr's too
2 parents 386afba + 86e5190 commit cd11aa5

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

core/src/Barcode.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
#ifdef ZXING_USE_ZINT
1818
#include <zint.h>
19+
void zint_symbol_deleter::operator()(zint_symbol* p) const noexcept
20+
{
21+
ZBarcode_Delete(p);
22+
}
1923
#else
2024
struct zint_symbol {};
2125
#endif
@@ -150,7 +154,7 @@ ImageView Result::symbol() const
150154
return {_symbol->row(0).begin(), _symbol->width(), _symbol->height(), ImageFormat::Lum};
151155
}
152156

153-
void Result::zint(std::unique_ptr<zint_symbol>&& z)
157+
void Result::zint(unique_zint_symbol&& z)
154158
{
155159
_zint = std::shared_ptr(std::move(z));
156160
}

core/src/Barcode.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ extern "C" struct zint_symbol;
2222
namespace ZXing {
2323
class BitMatrix;
2424
}
25+
26+
struct zint_symbol_deleter
27+
{
28+
void operator()(zint_symbol* p) const noexcept;
29+
};
30+
using unique_zint_symbol = std::unique_ptr<zint_symbol, zint_symbol_deleter>;
2531
#endif
2632

2733
#include <string>
@@ -171,7 +177,7 @@ class Result
171177
#ifdef ZXING_EXPERIMENTAL_API
172178
void symbol(BitMatrix&& bits);
173179
ImageView symbol() const;
174-
void zint(std::unique_ptr<zint_symbol>&& z);
180+
void zint(unique_zint_symbol&& z);
175181
zint_symbol* zint() const { return _zint.get(); }
176182
#endif
177183

core/src/WriteBarcode.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
#ifdef ZXING_USE_ZINT
1818

1919
#include <zint.h>
20-
template <>
21-
struct std::default_delete<zint_symbol>
22-
{
23-
void operator()(zint_symbol* p) const noexcept { ZBarcode_Delete(p); }
24-
};
2520

2621
#else
2722

@@ -41,7 +36,7 @@ struct CreatorOptions::Data
4136
// symbol size (qrcode, datamatrix, etc), map from I, 'WxH'
4237
// structured_append (idx, cnt, ID)
4338

44-
mutable std::unique_ptr<zint_symbol> zint;
39+
mutable unique_zint_symbol zint;
4540

4641
#if __cplusplus <= 201703L || defined(__APPLE__)
4742
Data(BarcodeFormat f) : format(f) {}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy