File: fix-static-variable-delete.patch

package info (click to toggle)
rlottie 0.1%2Bdfsg-4.3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,948 kB
  • sloc: cpp: 20,376; asm: 221; ansic: 194; makefile: 16
file content (92 lines) | stat: -rw-r--r-- 2,232 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Description: Remove default constructor implementation
 vcow_ptr is a rlottie-specific implementation of the shared pointer.
 It provides a default constructor containing a static variable that is 
 potentially deleted in the destructor. Remove constructor implementation in
 order to avoid undefined behavior.
Author: Vladimir Petko <vladimir.petko@canonical.com>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1032481
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/rlottie/+bug/2009551
Last-Update: 2023-03-07
--- a/src/vector/vcowptr.h
+++ b/src/vector/vcowptr.h
@@ -35,21 +35,18 @@
 
         T mValue;
     };
-    model* mModel;
-
+    model* mModel{};
 public:
     using element_type = T;
 
-    vcow_ptr()
-    {
-        static model default_s;
-        mModel = &default_s;
-        ++mModel->mRef;
-    }
+    vcow_ptr() = default;
 
     ~vcow_ptr()
     {
-        if (mModel && (--mModel->mRef == 0)) delete mModel;
+        if (mModel && (--mModel->mRef == 0)) {
+            delete mModel;
+            mModel = nullptr;
+        } 
     }
 
     template <class... Args>
@@ -59,12 +56,14 @@
 
     vcow_ptr(const vcow_ptr& x) noexcept : mModel(x.mModel)
     {
-        assert(mModel);
+        if (mModel == nullptr)
+            return;
         ++mModel->mRef;
     }
     vcow_ptr(vcow_ptr&& x) noexcept : mModel(x.mModel)
     {
-        assert(mModel);
+        if (mModel == nullptr)
+            return;
         x.mModel = nullptr;
     }
 
@@ -87,14 +86,16 @@
 
     std::size_t refCount() const noexcept
     {
-        assert(mModel);
+        if (mModel == nullptr)
+            return 0;
 
         return mModel->mRef;
     }
 
     bool unique() const noexcept
     {
-        assert(mModel);
+        if (mModel == nullptr)
+            return false;
 
         return mModel->mRef == 1;
     }
@@ -103,12 +104,15 @@
     {
         if (!unique()) *this = vcow_ptr(read());
 
+        assert(mModel);
         return mModel->mValue;
     }
 
     auto read() const noexcept -> const element_type&
     {
-        assert(mModel);
+        static model default_s{};
+        if (mModel == nullptr)
+            return default_s.mValue;
 
         return mModel->mValue;
     }