Guard against garbage collection in bytes (fixes #498)
This commit is contained in:
@@ -29,6 +29,7 @@ namespace lime {
|
|||||||
|
|
||||||
unsigned char *_data;
|
unsigned char *_data;
|
||||||
int _length;
|
int _length;
|
||||||
|
value *_root;
|
||||||
value _value;
|
value _value;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace lime {
|
|||||||
_data = 0;
|
_data = 0;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
_value = 0;
|
_value = 0;
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ namespace lime {
|
|||||||
_data = 0;
|
_data = 0;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
_value = 0;
|
_value = 0;
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
Resize (size);
|
Resize (size);
|
||||||
|
|
||||||
@@ -61,6 +63,11 @@ namespace lime {
|
|||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
|
_data = 0;
|
||||||
|
_length = 0;
|
||||||
|
_value = 0;
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
Set (bytes);
|
Set (bytes);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -73,6 +80,7 @@ namespace lime {
|
|||||||
_data = 0;
|
_data = 0;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
_value = 0;
|
_value = 0;
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
FILE_HANDLE *file = lime::fopen (path, "rb");
|
FILE_HANDLE *file = lime::fopen (path, "rb");
|
||||||
|
|
||||||
@@ -102,6 +110,11 @@ namespace lime {
|
|||||||
|
|
||||||
initialize ();
|
initialize ();
|
||||||
|
|
||||||
|
_data = 0;
|
||||||
|
_length = 0;
|
||||||
|
_value = 0;
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
Set (data);
|
Set (data);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -109,11 +122,12 @@ namespace lime {
|
|||||||
|
|
||||||
Bytes::~Bytes () {
|
Bytes::~Bytes () {
|
||||||
|
|
||||||
//if (!_value && _data) {
|
if (_root) {
|
||||||
//
|
|
||||||
//free (_data);
|
*_root = 0;
|
||||||
//
|
free_root (_root);
|
||||||
//}
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,6 +160,8 @@ namespace lime {
|
|||||||
if (!_value) {
|
if (!_value) {
|
||||||
|
|
||||||
_value = alloc_empty_object ();
|
_value = alloc_empty_object ();
|
||||||
|
_root = alloc_root ();
|
||||||
|
*_root = _value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,9 +220,20 @@ namespace lime {
|
|||||||
_data = 0;
|
_data = 0;
|
||||||
_value = 0;
|
_value = 0;
|
||||||
|
|
||||||
|
if (_root) {
|
||||||
|
|
||||||
|
*_root = 0;
|
||||||
|
free_root (_root);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
_value = bytes;
|
_value = bytes;
|
||||||
|
_root = alloc_root ();
|
||||||
|
*_root = _value;
|
||||||
_length = val_int (val_field (bytes, id_length));
|
_length = val_int (val_field (bytes, id_length));
|
||||||
|
|
||||||
if (_length > 0) {
|
if (_length > 0) {
|
||||||
@@ -248,6 +275,15 @@ namespace lime {
|
|||||||
_data = 0;
|
_data = 0;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
|
|
||||||
|
if (_root) {
|
||||||
|
|
||||||
|
*_root = 0;
|
||||||
|
free_root (_root);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_root = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user