1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

g10: Fix memory leak in enum_secret_keys.

* g10/skclist.c (enum_secret_keys): Don't forget to call
free_public_key in the error return paths.

--

Reported-by: Philippe Antoine
GnuPG-bug-id: 4140
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2018-09-14 07:55:20 +09:00
parent 69bab1cba0
commit 64c5c45e2a

View File

@ -345,7 +345,11 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
/* Make a new context. */ /* Make a new context. */
c = xtrycalloc (1, sizeof *c); c = xtrycalloc (1, sizeof *c);
if (!c) if (!c)
return gpg_error_from_syserror (); {
err = gpg_error_from_syserror ();
free_public_key (sk);
return err;
}
*context = c; *context = c;
} }
@ -363,7 +367,10 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
} }
if (c->eof) if (c->eof)
return gpg_error (GPG_ERR_EOF); {
free_public_key (sk);
return gpg_error (GPG_ERR_EOF);
}
for (;;) for (;;)
{ {
@ -475,6 +482,7 @@ enum_secret_keys (ctrl_t ctrl, void **context, PKT_public_key *sk)
default: /* No more names to check - stop. */ default: /* No more names to check - stop. */
c->eof = 1; c->eof = 1;
free_public_key (sk);
return gpg_error (GPG_ERR_EOF); return gpg_error (GPG_ERR_EOF);
} }
} }