g10: Don't leak memory if we fail to initialize a new database handle.
[gnupg.git] / g10 / delkey.c
index 3de705d..063de78 100644 (file)
@@ -111,6 +111,15 @@ do_delete_key( const char *username, int secret, int force, int *r_sec_avail )
         err = 0;
     }
 
+  if (secret && !have_secret_key_with_kid (keyid))
+    {
+      err = gpg_error (GPG_ERR_NOT_FOUND);
+      log_error (_("key \"%s\" not found: %s\n"), username, gpg_strerror (err));
+      write_status_text (STATUS_DELETE_PROBLEM, "1");
+      goto leave;
+    }
+
+
   if (opt.batch && exactmatch)
     okay++;
   else if (opt.batch && secret)