session BUGFIX freeing last items in arrays
diff --git a/src/session_client_ssh.c b/src/session_client_ssh.c
index ae47917..7e5f6e3 100644
--- a/src/session_client_ssh.c
+++ b/src/session_client_ssh.c
@@ -637,9 +637,15 @@
free(opts->keys[idx].privkey_path);
--opts->key_count;
-
- memcpy(opts->keys + idx, opts->keys + opts->key_count, sizeof *opts->keys);
- opts->keys = realloc(opts->keys, opts->key_count * sizeof *opts->keys);
+ if (idx < opts->key_count) {
+ memcpy(&opts->keys[idx], &opts->keys[opts->key_count], sizeof *opts->keys);
+ }
+ if (opts->key_count) {
+ opts->keys = realloc(opts->keys, opts->key_count * sizeof *opts->keys);
+ } else {
+ free(opts->keys);
+ opts->keys = NULL;
+ }
return 0;
}