diff --git a/project/include/utils/Bytes.h b/project/include/utils/Bytes.h index d680b83c6..4ef8178e3 100644 --- a/project/include/utils/Bytes.h +++ b/project/include/utils/Bytes.h @@ -29,6 +29,7 @@ namespace lime { unsigned char *_data; int _length; + value *_root; value _value; diff --git a/project/src/utils/Bytes.cpp b/project/src/utils/Bytes.cpp index 15912af29..ae49b0761 100644 --- a/project/src/utils/Bytes.cpp +++ b/project/src/utils/Bytes.cpp @@ -40,6 +40,7 @@ namespace lime { _data = 0; _length = 0; _value = 0; + _root = 0; } @@ -51,6 +52,7 @@ namespace lime { _data = 0; _length = 0; _value = 0; + _root = 0; Resize (size); @@ -61,6 +63,11 @@ namespace lime { initialize (); + _data = 0; + _length = 0; + _value = 0; + _root = 0; + Set (bytes); } @@ -73,6 +80,7 @@ namespace lime { _data = 0; _length = 0; _value = 0; + _root = 0; FILE_HANDLE *file = lime::fopen (path, "rb"); @@ -102,6 +110,11 @@ namespace lime { initialize (); + _data = 0; + _length = 0; + _value = 0; + _root = 0; + Set (data); } @@ -109,11 +122,12 @@ namespace lime { Bytes::~Bytes () { - //if (!_value && _data) { - // - //free (_data); - // - //} + if (_root) { + + *_root = 0; + free_root (_root); + + } } @@ -146,6 +160,8 @@ namespace lime { if (!_value) { _value = alloc_empty_object (); + _root = alloc_root (); + *_root = _value; } @@ -204,9 +220,20 @@ namespace lime { _data = 0; _value = 0; + if (_root) { + + *_root = 0; + free_root (_root); + + } + + _root = 0; + } else { _value = bytes; + _root = alloc_root (); + *_root = _value; _length = val_int (val_field (bytes, id_length)); if (_length > 0) { @@ -248,6 +275,15 @@ namespace lime { _data = 0; _length = 0; + if (_root) { + + *_root = 0; + free_root (_root); + + } + + _root = 0; + } }