Found and fixed a memory leak in the rope strings
Also fixed a bit manipulation error in the GC.
This commit is contained in:
+1
-1
@@ -88,7 +88,7 @@ TOY_API void Toy_collectBucketGarbage(Toy_Bucket** bucketHandle) {
|
||||
gc = false;
|
||||
break;
|
||||
}
|
||||
ptr += (*((int*)(ptr)) ^ 1) + 4; //XOR to remove the 'free' flag from the size
|
||||
ptr += ((*((int*)ptr) | 1) ^ 1) + 4; //OR + XOR to remove the 'free' flag from the size
|
||||
}
|
||||
|
||||
//free this link, if its been entirely released
|
||||
|
||||
@@ -193,6 +193,8 @@ void Toy_assignScope(Toy_Scope* scope, Toy_String* key, Toy_Value value) {
|
||||
return;
|
||||
}
|
||||
|
||||
Toy_freeValue(entryPtr->value);
|
||||
|
||||
entryPtr->value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,18 @@ static void incrementRefCount(Toy_String* str) {
|
||||
static void decrementRefCount(Toy_String* str) {
|
||||
str->info.refCount--;
|
||||
if (str->info.type == TOY_STRING_NODE) {
|
||||
//the parent of this node triggered a decrement across the whole tree
|
||||
decrementRefCount(str->node.left);
|
||||
decrementRefCount(str->node.right);
|
||||
}
|
||||
if (str->info.refCount == 0) {
|
||||
if (str->info.type == TOY_STRING_NODE) {
|
||||
//THIS node has triggered the decrement, so run this again
|
||||
decrementRefCount(str->node.left);
|
||||
decrementRefCount(str->node.right);
|
||||
}
|
||||
|
||||
//mark this memory as unused
|
||||
Toy_releaseBucketPartition((void*)str);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -210,7 +210,7 @@ static void processAssign(Toy_VM* vm) {
|
||||
Toy_Value name = Toy_popStack(&vm->stack);
|
||||
|
||||
//assign it
|
||||
Toy_assignScope(vm->scope, TOY_VALUE_AS_STRING(name), Toy_copyValue(&vm->memoryBucket, value)); //scope now owns the value, doesn't need to be freed
|
||||
Toy_assignScope(vm->scope, TOY_VALUE_AS_STRING(name), Toy_copyValue(&vm->memoryBucket, value));
|
||||
|
||||
//in case of chaining, leave a copy on the stack
|
||||
bool chainedAssignment = READ_BYTE(vm);
|
||||
@@ -220,6 +220,7 @@ static void processAssign(Toy_VM* vm) {
|
||||
|
||||
//cleanup
|
||||
Toy_freeValue(name);
|
||||
Toy_freeValue(value);
|
||||
}
|
||||
|
||||
static void processAssignCompound(Toy_VM* vm) {
|
||||
|
||||
Reference in New Issue
Block a user