From f3c7872fed5e0782438d186ac88c63035a637462 Mon Sep 17 00:00:00 2001
From: Sergey Poznyakoff <gray@gnu.org>
Date: Thu, 18 Nov 2021 12:22:59 +0200
Subject: Fix gdbmtool import command

* src/gdbmshell.c (import_handler): Fix option addressing (see
https://puszcza.gnu.org.ua/bugs/?535).
Fix freeing of the uninitialized variable.
---
 src/gdbmshell.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/gdbmshell.c b/src/gdbmshell.c
index 08042ce..96b5844 100644
--- a/src/gdbmshell.c
+++ b/src/gdbmshell.c
@@ -661,7 +661,7 @@ err_printer (void *data GDBM_ARG_UNUSED, char const *fmt, ...)
   fprintf (stderr, "\n");
 }
 
-/* recover sumamry verbose backup max-failed-keys=N max-failed-buckets=N max-failures=N */
+/* recover summary verbose backup max-failed-keys=N max-failed-buckets=N max-failures=N */
 static int
 recover_handler (struct command_param *param, struct command_environ *cenv)
 {
@@ -1585,7 +1585,7 @@ import_handler (struct command_param *param,
   int rc = GDBMSHELL_OK;
   char *file_name;
   
-  for (i = 0; i < param->argc; i++)
+  for (i = 1; i < param->argc; i++)
     {
       if (strcmp (PARAM_STRING (param, i), "replace") == 0)
 	 flag = GDBM_REPLACE;
@@ -1637,7 +1637,6 @@ import_handler (struct command_param *param,
       return GDBMSHELL_GDBM_ERR;
     }
 
-  free (file_name);
   if (gdbm_setopt (gdbm_file, GDBM_GETDBNAME, &file_name, sizeof (file_name)))
     {
       dberror ("%s", "GDBM_GETDBNAME");
-- 
cgit v1.2.1

