summaryrefslogtreecommitdiffstats
path: root/g10/call-agent.c
diff options
context:
space:
mode:
authorJakub Jelen <jjelen@redhat.com>2021-04-12 20:05:48 +0200
committerWerner Koch <wk@gnupg.org>2021-05-20 14:42:29 +0200
commitfa0771f609b5fcb104c64a11aefc501b7a91696d (patch)
tree6e2929ab9eb917f4d2c9e2f44f456bcee06de838 /g10/call-agent.c
parentdirmgr: Avoid double free (diff)
downloadgnupg2-fa0771f609b5fcb104c64a11aefc501b7a91696d.tar.xz
gnupg2-fa0771f609b5fcb104c64a11aefc501b7a91696d.zip
g10: Avoid memory leaks
* g10/call-agent.c (card_keyinfo_cb): free keyinfo. Restructure to avoid backward gotos. * g10/keyedit.c (menu_set_keyserver_url): properly enclose the block * g10/keygen.c (gen_card_key): free pk and pkt -- Signed-off-by: Jakub Jelen <jjelen@redhat.com> GnuPG-bug-id: 5393 Additional changes: - Restructure to avoid backward gotos. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'g10/call-agent.c')
-rw-r--r--g10/call-agent.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c
index 782631c0d..8f4e44b32 100644
--- a/g10/call-agent.c
+++ b/g10/call-agent.c
@@ -1709,6 +1709,7 @@ card_keyinfo_cb (void *opaque, const char *line)
struct card_keyinfo_parm_s *parm = opaque;
const char *keyword = line;
int keywordlen;
+ keypair_info_t keyinfo = NULL;
for (keywordlen=0; *line && !spacep (line); line++, keywordlen++)
;
@@ -1719,7 +1720,6 @@ card_keyinfo_cb (void *opaque, const char *line)
{
const char *s;
int n;
- keypair_info_t keyinfo;
keypair_info_t *l_p = &parm->list;
while ((*l_p))
@@ -1727,23 +1727,13 @@ card_keyinfo_cb (void *opaque, const char *line)
keyinfo = xtrycalloc (1, sizeof *keyinfo);
if (!keyinfo)
- {
- alloc_error:
- if (!parm->error)
- parm->error = gpg_error_from_syserror ();
- return 0;
- }
+ goto alloc_error;
for (n=0,s=line; hexdigitp (s); s++, n++)
;
if (n != 40)
- {
- parm_error:
- if (!parm->error)
- parm->error = gpg_error (GPG_ERR_ASS_PARAMETER);
- return 0;
- }
+ goto parm_error;
memcpy (keyinfo->keygrip, line, 40);
keyinfo->keygrip[40] = 0;
@@ -1797,6 +1787,18 @@ card_keyinfo_cb (void *opaque, const char *line)
}
return err;
+
+ alloc_error:
+ xfree (keyinfo);
+ if (!parm->error)
+ parm->error = gpg_error_from_syserror ();
+ return 0;
+
+ parm_error:
+ xfree (keyinfo);
+ if (!parm->error)
+ parm->error = gpg_error (GPG_ERR_ASS_PARAMETER);
+ return 0;
}