Skip to content

Commit

Permalink
array: clear unused array slots after remove
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Nov 21, 2013
1 parent f1b9aef commit 31f4935
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ ni_route_array_remove(ni_route_array_t *nra, unsigned int index)
memmove(&nra->data[index], &nra->data[index + 1],
(nra->count - index) * sizeof(ni_route_t *));
nra->count--;
nra->data[nra->count] = NULL;

/* Don't bother with shrinking the array. It's not worth the trouble */
return rp;
Expand Down
1 change: 1 addition & 0 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ ni_socket_array_remove_at(ni_socket_array_t *array, unsigned int index)
memmove(&array->data[index], &array->data[index + 1],
(array->count - index) * sizeof(ni_socket_t *));
array->count--;
array->data[array->count] = NULL;

if (sock && sock->active == array)
sock->active = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ ni_updater_source_array_remove(ni_updater_source_array_t *usa, unsigned int inde
memmove(&usa->data[index], &usa->data[index + 1],
(usa->count - index) * sizeof(ni_updater_source_t *));
usa->count--;
usa->data[usa->count] = NULL;

/* Don't bother with shrinking the array. It's not worth the trouble */
return ptr;
Expand Down
1 change: 1 addition & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ ni_string_array_remove_index(ni_string_array_t *nsa, unsigned int pos)
/* Note: this also copies the NULL pointer following the last element */
memmove(&nsa->data[pos], &nsa->data[pos + 1], (nsa->count - pos) * sizeof(char *));
nsa->count--;
nsa->data[nsa->count] = NULL;

/* Don't bother with shrinking the array. It's not worth the trouble */
return 0;
Expand Down

0 comments on commit 31f4935

Please sign in to comment.