Skip to content

Commit

Permalink
Set struct _u_map elements to NULL on cleanup or init error #261
Browse files Browse the repository at this point in the history
  • Loading branch information
babelouest committed Apr 4, 2023
1 parent adf5f05 commit 0d4f7ab
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/u_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
int u_map_init(struct _u_map * u_map) {
if (u_map != NULL) {
u_map->nb_values = 0;
u_map->values = NULL;
u_map->lengths = NULL;
u_map->keys = o_malloc(sizeof(char *));
if (u_map->keys == NULL) {
y_log_message(Y_LOG_LEVEL_ERROR, "Ulfius - Error allocating memory for u_map->keys");
Expand All @@ -43,6 +45,7 @@ int u_map_init(struct _u_map * u_map) {
if (u_map->values == NULL) {
y_log_message(Y_LOG_LEVEL_ERROR, "Ulfius - Error allocating memory for u_map->values");
o_free(u_map->keys);
u_map->keys = NULL;
return U_ERROR_MEMORY;
}
u_map->values[0] = NULL;
Expand All @@ -52,6 +55,8 @@ int u_map_init(struct _u_map * u_map) {
y_log_message(Y_LOG_LEVEL_ERROR, "Ulfius - Error allocating memory for u_map->lengths");
o_free(u_map->keys);
o_free(u_map->values);
u_map->keys = NULL;
u_map->values = NULL;
return U_ERROR_MEMORY;
}
u_map->lengths[0] = 0;
Expand All @@ -72,6 +77,9 @@ int u_map_clean(struct _u_map * u_map) {
o_free(u_map->keys);
o_free(u_map->values);
o_free(u_map->lengths);
u_map->keys = NULL;
u_map->values = NULL;
u_map->lengths = NULL;
return U_OK;
} else {
return U_ERROR_PARAMS;
Expand Down

0 comments on commit 0d4f7ab

Please sign in to comment.