diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2024-11-07 15:34:39 -0800 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2024-11-07 15:34:39 -0800 |
commit | 589e691ba8503dd247aaeab76c1113f87c2ff980 (patch) | |
tree | 5d4132085ec8a277c2dd5fbef19cf38ff9e3cb76 /src/tests | |
parent | 6c066b6bbd4a44ae7c5874abf6bd3a3e04f76b88 (diff) | |
download | libbu++-589e691ba8503dd247aaeab76c1113f87c2ff980.tar.gz libbu++-589e691ba8503dd247aaeab76c1113f87c2ff980.tar.bz2 libbu++-589e691ba8503dd247aaeab76c1113f87c2ff980.tar.xz libbu++-589e691ba8503dd247aaeab76c1113f87c2ff980.zip |
Fixed long standing double-free bug in the cache.
I guess we don't delete stuff very often.
Diffstat (limited to '')
-rw-r--r-- | src/tests/cachedel.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/tests/cachedel.cpp b/src/tests/cachedel.cpp index 3fa3e86..f4cb1b5 100644 --- a/src/tests/cachedel.cpp +++ b/src/tests/cachedel.cpp | |||
@@ -21,6 +21,12 @@ public: | |||
21 | 21 | ||
22 | virtual ~Something() | 22 | virtual ~Something() |
23 | { | 23 | { |
24 | //Bu::println("Deleting %1").arg( this->toString() ); | ||
25 | } | ||
26 | |||
27 | void sayHi() | ||
28 | { | ||
29 | Bu::println("Hello %1").arg( toString() ); | ||
24 | } | 30 | } |
25 | 31 | ||
26 | virtual Bu::Uuid getKey() const | 32 | virtual Bu::Uuid getKey() const |
@@ -39,7 +45,7 @@ public: | |||
39 | changed(); | 45 | changed(); |
40 | } | 46 | } |
41 | 47 | ||
42 | virtual Bu::String toString() const=0; | 48 | virtual Bu::String toString() const=0;// { return Bu::String("ERROR"); }; |
43 | 49 | ||
44 | private: | 50 | private: |
45 | Bu::Uuid uId; | 51 | Bu::Uuid uId; |
@@ -60,6 +66,11 @@ public: | |||
60 | iNumber( iNumber ) | 66 | iNumber( iNumber ) |
61 | { | 67 | { |
62 | } | 68 | } |
69 | |||
70 | virtual ~SubSomethingA() | ||
71 | { | ||
72 | Bu::println("Deleting-A %1").arg( this->toString() ); | ||
73 | } | ||
63 | 74 | ||
64 | virtual Bu::String toString() const | 75 | virtual Bu::String toString() const |
65 | { | 76 | { |
@@ -84,6 +95,10 @@ public: | |||
84 | sString( sString ) | 95 | sString( sString ) |
85 | { | 96 | { |
86 | } | 97 | } |
98 | |||
99 | virtual ~SubSomethingB() | ||
100 | { | ||
101 | } | ||
87 | 102 | ||
88 | virtual Bu::String toString() const | 103 | virtual Bu::String toString() const |
89 | { | 104 | { |
@@ -187,6 +202,11 @@ int main( int, char *[] ) | |||
187 | Bu::MemBuf mbStore; | 202 | Bu::MemBuf mbStore; |
188 | SomethingCache c( mbStore ); | 203 | SomethingCache c( mbStore ); |
189 | 204 | ||
205 | { | ||
206 | SubSomethingA a("Test", 1); | ||
207 | a.sayHi(); | ||
208 | } | ||
209 | |||
190 | SomethingPtr ptr; | 210 | SomethingPtr ptr; |
191 | if( time(NULL)%2 ) | 211 | if( time(NULL)%2 ) |
192 | ptr = c.insert( new SubSomethingA("Hello", 55) ).cast<Something>(); | 212 | ptr = c.insert( new SubSomethingA("Hello", 55) ).cast<Something>(); |
@@ -211,6 +231,8 @@ int main( int, char *[] ) | |||
211 | c.erase( id ); | 231 | c.erase( id ); |
212 | Bu::println("p2 %1: %2").arg( id ).arg( c.has( id ) ); | 232 | Bu::println("p2 %1: %2").arg( id ).arg( c.has( id ) ); |
213 | 233 | ||
234 | Bu::println("Program listing over, leaving main scope."); | ||
235 | |||
214 | return 0; | 236 | return 0; |
215 | } | 237 | } |
216 | 238 | ||