mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
g10: Don't leak memory if we fail to initialize a new database handle.
* g10/keydb.c (keydb_new): If we fail to open a keyring or keybox correctly release all resources. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>.
This commit is contained in:
parent
360b699e9b
commit
04a6b903d0
21
g10/keydb.c
21
g10/keydb.c
@ -692,6 +692,7 @@ keydb_new (void)
|
||||
{
|
||||
KEYDB_HANDLE hd;
|
||||
int i, j;
|
||||
int die = 0;
|
||||
|
||||
if (DBG_CLOCK)
|
||||
log_clock ("keydb_new");
|
||||
@ -702,7 +703,7 @@ keydb_new (void)
|
||||
hd->is_reset = 1;
|
||||
|
||||
assert (used_resources <= MAX_KEYDB_RESOURCES);
|
||||
for (i=j=0; i < used_resources; i++)
|
||||
for (i=j=0; ! die && i < used_resources; i++)
|
||||
{
|
||||
switch (all_resources[i].type)
|
||||
{
|
||||
@ -712,10 +713,8 @@ keydb_new (void)
|
||||
hd->active[j].type = all_resources[i].type;
|
||||
hd->active[j].token = all_resources[i].token;
|
||||
hd->active[j].u.kr = keyring_new (all_resources[i].token);
|
||||
if (!hd->active[j].u.kr) {
|
||||
xfree (hd);
|
||||
return NULL; /* fixme: release all previously allocated handles*/
|
||||
}
|
||||
if (!hd->active[j].u.kr)
|
||||
die = 1;
|
||||
j++;
|
||||
break;
|
||||
case KEYDB_RESOURCE_TYPE_KEYBOX:
|
||||
@ -723,10 +722,7 @@ keydb_new (void)
|
||||
hd->active[j].token = all_resources[i].token;
|
||||
hd->active[j].u.kb = keybox_new_openpgp (all_resources[i].token, 0);
|
||||
if (!hd->active[j].u.kb)
|
||||
{
|
||||
xfree (hd);
|
||||
return NULL; /* fixme: release all previously allocated handles*/
|
||||
}
|
||||
die = 1;
|
||||
j++;
|
||||
break;
|
||||
}
|
||||
@ -734,6 +730,13 @@ keydb_new (void)
|
||||
hd->used = j;
|
||||
|
||||
active_handles++;
|
||||
|
||||
if (die)
|
||||
{
|
||||
keydb_release (hd);
|
||||
hd = NULL;
|
||||
}
|
||||
|
||||
return hd;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user