Fixed a memory leak in value_t::storage_t
This commit is contained in:
parent
5d50d895bf
commit
aeea1cb3e1
2 changed files with 18 additions and 14 deletions
|
|
@ -119,7 +119,7 @@ void value_t::set_type(type_t new_type)
|
||||||
if (! storage || storage->refc > 1)
|
if (! storage || storage->refc > 1)
|
||||||
storage = new storage_t;
|
storage = new storage_t;
|
||||||
else
|
else
|
||||||
storage->data = false; // destruct all other types
|
storage->destroy();
|
||||||
storage->type = new_type;
|
storage->type = new_type;
|
||||||
assert(is_type(new_type));
|
assert(is_type(new_type));
|
||||||
}
|
}
|
||||||
|
|
@ -911,7 +911,7 @@ void value_t::in_place_cast(type_t cast_type)
|
||||||
if (amt.is_null())
|
if (amt.is_null())
|
||||||
set_balance(balance_t());
|
set_balance(balance_t());
|
||||||
else
|
else
|
||||||
set_balance(as_amount()); // creates temporary
|
set_balance(as_amount());
|
||||||
return;
|
return;
|
||||||
case STRING:
|
case STRING:
|
||||||
if (amt.is_null())
|
if (amt.is_null())
|
||||||
|
|
|
||||||
28
src/value.h
28
src/value.h
|
|
@ -166,19 +166,8 @@ private:
|
||||||
*/
|
*/
|
||||||
~storage_t() {
|
~storage_t() {
|
||||||
TRACE_DTOR(value_t::storage_t);
|
TRACE_DTOR(value_t::storage_t);
|
||||||
DEBUG("value.storage.refcount", "Destroying " << this);
|
|
||||||
assert(refc == 0);
|
assert(refc == 0);
|
||||||
|
destroy();
|
||||||
switch (type) {
|
|
||||||
case BALANCE:
|
|
||||||
checked_delete(boost::get<balance_t *>(data));
|
|
||||||
break;
|
|
||||||
case SEQUENCE:
|
|
||||||
checked_delete(boost::get<sequence_t *>(data));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -218,6 +207,21 @@ private:
|
||||||
friend inline void intrusive_ptr_release(value_t::storage_t * storage) {
|
friend inline void intrusive_ptr_release(value_t::storage_t * storage) {
|
||||||
storage->release();
|
storage->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void destroy() {
|
||||||
|
DEBUG("value.storage.refcount", "Destroying " << this);
|
||||||
|
switch (type) {
|
||||||
|
case BALANCE:
|
||||||
|
checked_delete(boost::get<balance_t *>(data));
|
||||||
|
break;
|
||||||
|
case SEQUENCE:
|
||||||
|
checked_delete(boost::get<sequence_t *>(data));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
type = VOID;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue