mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
dirmngr: Fix memory leak.
* dirmngr/ldap.c (start_cert_fetch_ldap): Avoid leaking all malloc'ed arguments. -- Found using the Clang Static Analyzer. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
a1650b1edf
commit
b223cde311
@ -525,8 +525,9 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
|
|||||||
const char *user;
|
const char *user;
|
||||||
const char *pass;
|
const char *pass;
|
||||||
const char *base;
|
const char *base;
|
||||||
const char *argv[50];
|
char *argv[50];
|
||||||
int argc;
|
int argc;
|
||||||
|
int argc_malloced;
|
||||||
char portbuf[30], timeoutbuf[30];
|
char portbuf[30], timeoutbuf[30];
|
||||||
|
|
||||||
|
|
||||||
@ -583,6 +584,8 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
|
|||||||
argv[argc++] = user;
|
argv[argc++] = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* All entries in argv from this index on are malloc'ed. */
|
||||||
|
argc_malloced = argc;
|
||||||
|
|
||||||
for (; patterns; patterns = patterns->next)
|
for (; patterns; patterns = patterns->next)
|
||||||
{
|
{
|
||||||
@ -602,8 +605,8 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
|
|||||||
{
|
{
|
||||||
log_error (_("start_cert_fetch: invalid pattern '%s'\n"),
|
log_error (_("start_cert_fetch: invalid pattern '%s'\n"),
|
||||||
patterns->d);
|
patterns->d);
|
||||||
/* fixme: cleanup argv. */
|
err = gpg_error (GPG_ERR_INV_USER_ID);
|
||||||
return gpg_error (GPG_ERR_INV_USER_ID);
|
goto leave;
|
||||||
}
|
}
|
||||||
if ((sl->flags & 1))
|
if ((sl->flags & 1))
|
||||||
err = make_url (&url, sl->d, "objectClass=*");
|
err = make_url (&url, sl->d, "objectClass=*");
|
||||||
@ -611,17 +614,17 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
|
|||||||
err = make_url (&url, base, sl->d);
|
err = make_url (&url, base, sl->d);
|
||||||
free_strlist (sl);
|
free_strlist (sl);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
goto leave;
|
||||||
/* fixme: cleanup argv. */
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
argv[argc++] = url;
|
argv[argc++] = url;
|
||||||
}
|
}
|
||||||
argv[argc] = NULL;
|
argv[argc] = NULL;
|
||||||
|
|
||||||
*context = xtrycalloc (1, sizeof **context);
|
*context = xtrycalloc (1, sizeof **context);
|
||||||
if (!*context)
|
if (!*context)
|
||||||
return gpg_error_from_errno (errno);
|
{
|
||||||
|
err = gpg_error_from_errno (errno);
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
|
||||||
err = ldap_wrapper (ctrl, &(*context)->reader, argv);
|
err = ldap_wrapper (ctrl, &(*context)->reader, argv);
|
||||||
|
|
||||||
@ -631,6 +634,9 @@ start_cert_fetch_ldap (ctrl_t ctrl, cert_fetch_context_t *context,
|
|||||||
*context = NULL;
|
*context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leave:
|
||||||
|
for (; argc_malloced < argc; argc_malloced++)
|
||||||
|
xfree (argv[argc_malloced]);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user