mirror of
https://github.com/theoludwig/libcproject.git
synced 2025-05-21 23:21:15 +02:00
fix: more memory issues thanks to -fsanitize=address flag
Work In Progress #5
This commit is contained in:
@ -56,7 +56,9 @@ string_t convert_number_to_string(const long long integer) {
|
||||
string_value[index++] = '-';
|
||||
}
|
||||
string_value[index] = '\0';
|
||||
return string_reverse(string_value);
|
||||
char* result = string_reverse(string_value);
|
||||
free(string_value);
|
||||
return result;
|
||||
}
|
||||
|
||||
string_t convert_number_from_base_10_to_base(unsigned long long number, unsigned int base) {
|
||||
|
@ -221,6 +221,7 @@ string_t *hash_map_get_keys(struct hash_map *hash_map) {
|
||||
void hash_map_free(struct hash_map *hash_map) {
|
||||
for (size_t index = 0; index < hash_map->capacity; index++) {
|
||||
if (hash_map->items[index] != NULL) {
|
||||
free(hash_map->items[index]->head->data);
|
||||
linked_list_free(hash_map->items[index]);
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,7 @@ struct linked_list *linked_list_reverse(struct linked_list *list) {
|
||||
linked_list_add_after_last(linked_list_reversed, stack_node_current->data);
|
||||
stack_node_current = stack_node_current->next;
|
||||
}
|
||||
stack_free(stack);
|
||||
return linked_list_reversed;
|
||||
}
|
||||
|
||||
|
@ -192,11 +192,9 @@ string_t* string_split(const string_t string_value, char separator, size_t* resu
|
||||
size_t index_result = 0;
|
||||
string_t current = malloc(sizeof(char) * (string_length + 1));
|
||||
string_t* result = NULL;
|
||||
|
||||
if (current == NULL) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
while (index_string < string_length) {
|
||||
if (string_value[index_string] == separator) {
|
||||
current[index_current] = '\0';
|
||||
@ -206,7 +204,7 @@ string_t* string_split(const string_t string_value, char separator, size_t* resu
|
||||
}
|
||||
result[index_result] = string_copy(current);
|
||||
index_result++;
|
||||
index_current = 0; // Reset index_current for the next substring
|
||||
index_current = 0;
|
||||
} else {
|
||||
current[index_current] = string_value[index_string];
|
||||
index_current++;
|
||||
@ -281,6 +279,7 @@ bool string_get_has_unique_characters(const string_t string_value) {
|
||||
string_t key = convert_character_to_string(character);
|
||||
if (hash_map_contains_key(characters_already_seen, key)) {
|
||||
has_unique = false;
|
||||
free(key);
|
||||
} else {
|
||||
hash_map_add(characters_already_seen, key, (void*)true);
|
||||
}
|
||||
@ -342,6 +341,7 @@ string_t string_get_formatted_number(const long long number, string_t separator)
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
free(number_string);
|
||||
result[formatted_length] = '\0';
|
||||
result = string_reverse(result);
|
||||
if (is_negative) {
|
||||
|
Reference in New Issue
Block a user