fix memory leak that occures when converting a hashmap to a string in debug mode
This commit is contained in:
@@ -134,7 +134,8 @@ void run_call(ArgonObject *original_object, size_t argc, ArgonObject **argv,
|
|||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
if (CStackFrame) {
|
if (CStackFrame) {
|
||||||
ArgonObject * registers[MAX_REGISTERS]; // fixed on the stack for speed purposes
|
ArgonObject ** registers = ar_alloc(object->value.argon_fn->translated.registerCount *
|
||||||
|
sizeof(ArgonObject *)); // fixed on the stack for speed purposes
|
||||||
StackFrame new_stackFrame = {
|
StackFrame new_stackFrame = {
|
||||||
{object->value.argon_fn->translated.registerCount,
|
{object->value.argon_fn->translated.registerCount,
|
||||||
object->value.argon_fn->translated.registerAssignment,
|
object->value.argon_fn->translated.registerAssignment,
|
||||||
|
|||||||
@@ -39,18 +39,18 @@ static int compare_node_asc(const void *a, const void *b) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC ***array,
|
struct node_GC ** hashmap_GC_to_array(struct hashmap_GC *t,
|
||||||
size_t *array_length) {
|
size_t *array_length) {
|
||||||
size_t array_size = 8;
|
size_t array_size = 8;
|
||||||
*array_length = 0;
|
*array_length = 0;
|
||||||
*array = ar_alloc(array_size * sizeof(struct node_GC*));
|
struct node_GC ** array = ar_alloc(array_size * sizeof(struct node_GC*));
|
||||||
|
|
||||||
for (size_t i = 0; i < t->inline_count; i++) {
|
for (size_t i = 0; i < t->inline_count; i++) {
|
||||||
if (*array_length >= array_size) {
|
if (*array_length >= array_size) {
|
||||||
array_size *= 2;
|
array_size *= 2;
|
||||||
*array = ar_realloc(*array, array_size * sizeof(struct node_GC*));
|
array = ar_realloc(array, array_size * sizeof(struct node_GC*));
|
||||||
}
|
}
|
||||||
(*array)[(*array_length)++] = &t->inline_values[i];
|
array[(*array_length)++] = &t->inline_values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < t->size; i++) {
|
for (size_t i = 0; i < t->size; i++) {
|
||||||
@@ -59,14 +59,15 @@ void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC ***array,
|
|||||||
while (temp) {
|
while (temp) {
|
||||||
if (*array_length >= array_size) {
|
if (*array_length >= array_size) {
|
||||||
array_size *= 2;
|
array_size *= 2;
|
||||||
*array = ar_realloc(*array, array_size * sizeof(struct node_GC*));
|
array = ar_realloc(array, array_size * sizeof(struct node_GC*));
|
||||||
}
|
}
|
||||||
(*array)[(*array_length)++] = temp;
|
array[(*array_length)++] = temp;
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(*array, *array_length, sizeof(struct node_GC*), compare_node_asc);
|
qsort(array, *array_length, sizeof(struct node_GC*), compare_node_asc);
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_hashmap_GC(struct hashmap_GC *t) {
|
void clear_hashmap_GC(struct hashmap_GC *t) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ struct hashmap_GC *createHashmap_GC();
|
|||||||
|
|
||||||
void clear_hashmap_GC(struct hashmap_GC *t);
|
void clear_hashmap_GC(struct hashmap_GC *t);
|
||||||
|
|
||||||
void hashmap_GC_to_array(struct hashmap_GC *t, struct node_GC ***array,
|
struct node_GC ** hashmap_GC_to_array(struct hashmap_GC *t,
|
||||||
size_t *array_length);
|
size_t *array_length);
|
||||||
|
|
||||||
int hashCode_GC(struct hashmap_GC *t, uint64_t hash);
|
int hashCode_GC(struct hashmap_GC *t, uint64_t hash);
|
||||||
|
|||||||
@@ -45,16 +45,15 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc,
|
|||||||
ArgonObject *object = argv[0];
|
ArgonObject *object = argv[0];
|
||||||
size_t string_length = 0;
|
size_t string_length = 0;
|
||||||
char *string = NULL;
|
char *string = NULL;
|
||||||
struct node_GC **keys;
|
size_t nodes_length;
|
||||||
size_t keys_length;
|
struct node_GC ** nodes = hashmap_GC_to_array(object->value.as_hashmap, &nodes_length);
|
||||||
hashmap_GC_to_array(object->value.as_hashmap, &keys, &keys_length);
|
|
||||||
char *string_obj = "{";
|
char *string_obj = "{";
|
||||||
size_t length = strlen(string_obj);
|
size_t length = strlen(string_obj);
|
||||||
string = realloc(string, string_length + length);
|
string = realloc(string, string_length + length);
|
||||||
memcpy(string + string_length, string_obj, length);
|
memcpy(string + string_length, string_obj, length);
|
||||||
string_length += length;
|
string_length += length;
|
||||||
for (size_t i = 0; i < keys_length; i++) {
|
for (size_t i = 0; i < nodes_length; i++) {
|
||||||
struct node_GC *node = keys[i];
|
struct node_GC *node = nodes[i];
|
||||||
ArgonObject *key = node->key;
|
ArgonObject *key = node->key;
|
||||||
ArgonObject *value = node->val;
|
ArgonObject *value = node->val;
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ ArgonObject *create_ARGON_DICTIONARY_TYPE___string__(size_t argc,
|
|||||||
string_length += length;
|
string_length += length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i != keys_length - 1) {
|
if (i != nodes_length - 1) {
|
||||||
char *string_obj = ", ";
|
char *string_obj = ", ";
|
||||||
size_t length = strlen(string_obj);
|
size_t length = strlen(string_obj);
|
||||||
string = realloc(string, string_length + length);
|
string = realloc(string, string_length + length);
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
while (true) do
|
while (true) do
|
||||||
string(global)
|
term.log(global)
|
||||||
Reference in New Issue
Block a user