fixing minor memory leak
This commit is contained in:
parent
7e6b7e6b53
commit
64d2ca9e5c
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
This file is part of TALER
|
||||||
Copyright (C) 2014 Christian Grothoff (and other contributing authors)
|
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
|
||||||
|
|
||||||
TALER is free software; you can redistribute it and/or modify it under the
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
terms of the GNU General Public License as published by the Free Software
|
terms of the GNU General Public License as published by the Free Software
|
||||||
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file key_io.c
|
* @file mint/key_io.c
|
||||||
* @brief I/O operations for the Mint's private keys
|
* @brief I/O operations for the Mint's private keys
|
||||||
* @author Florian Dold
|
* @author Florian Dold
|
||||||
* @author Benedikt Mueller
|
* @author Benedikt Mueller
|
||||||
@ -33,14 +33,6 @@ struct SignkeysIterateContext
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct DenomkeysIterateContext
|
|
||||||
{
|
|
||||||
const char *alias;
|
|
||||||
TALER_MINT_DenomkeyIterator it;
|
|
||||||
void *it_cls;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
signkeys_iterate_dir_iter (void *cls,
|
signkeys_iterate_dir_iter (void *cls,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
@ -56,7 +48,7 @@ signkeys_iterate_dir_iter (void *cls,
|
|||||||
if (nread != sizeof (struct TALER_MINT_SignKeyIssuePriv))
|
if (nread != sizeof (struct TALER_MINT_SignKeyIssuePriv))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
||||||
"Invalid signkey file: '%s'\n",
|
"Invalid signkey file: `%s'\n",
|
||||||
filename);
|
filename);
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
@ -68,19 +60,23 @@ signkeys_iterate_dir_iter (void *cls,
|
|||||||
|
|
||||||
int
|
int
|
||||||
TALER_MINT_signkeys_iterate (const char *mint_base_dir,
|
TALER_MINT_signkeys_iterate (const char *mint_base_dir,
|
||||||
TALER_MINT_SignkeyIterator it, void *cls)
|
TALER_MINT_SignkeyIterator it,
|
||||||
|
void *it_cls)
|
||||||
{
|
{
|
||||||
char *signkey_dir;
|
char *signkey_dir;
|
||||||
size_t len;
|
|
||||||
struct SignkeysIterateContext skc;
|
struct SignkeysIterateContext skc;
|
||||||
|
int ret;
|
||||||
|
|
||||||
len = GNUNET_asprintf (&signkey_dir, ("%s" DIR_SEPARATOR_STR DIR_SIGNKEYS), mint_base_dir);
|
GNUNET_asprintf (&signkey_dir,
|
||||||
GNUNET_assert (len > 0);
|
"%s" DIR_SEPARATOR_STR DIR_SIGNKEYS,
|
||||||
|
mint_base_dir);
|
||||||
skc.it = it;
|
skc.it = it;
|
||||||
skc.it_cls = cls;
|
skc.it_cls = it_cls;
|
||||||
|
ret = GNUNET_DISK_directory_scan (signkey_dir,
|
||||||
return GNUNET_DISK_directory_scan (signkey_dir, &signkeys_iterate_dir_iter, &skc);
|
&signkeys_iterate_dir_iter,
|
||||||
|
&skc);
|
||||||
|
GNUNET_free (signkey_dir);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -104,7 +100,8 @@ TALER_MINT_read_denom_key (const char *filename,
|
|||||||
ret = GNUNET_SYSERR;
|
ret = GNUNET_SYSERR;
|
||||||
data = NULL;
|
data = NULL;
|
||||||
offset = sizeof (struct TALER_MINT_DenomKeyIssuePriv)
|
offset = sizeof (struct TALER_MINT_DenomKeyIssuePriv)
|
||||||
- offsetof (struct TALER_MINT_DenomKeyIssuePriv, issue.signature);
|
- offsetof (struct TALER_MINT_DenomKeyIssuePriv,
|
||||||
|
issue.signature);
|
||||||
if (GNUNET_OK != GNUNET_DISK_file_size (filename,
|
if (GNUNET_OK != GNUNET_DISK_file_size (filename,
|
||||||
&size,
|
&size,
|
||||||
GNUNET_YES,
|
GNUNET_YES,
|
||||||
@ -161,16 +158,18 @@ TALER_MINT_write_denom_key (const char *filename,
|
|||||||
GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)))
|
GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
wsize = sizeof (struct TALER_MINT_DenomKeyIssuePriv)
|
wsize = sizeof (struct TALER_MINT_DenomKeyIssuePriv)
|
||||||
- offsetof (struct TALER_MINT_DenomKeyIssuePriv, issue.signature);
|
- offsetof (struct TALER_MINT_DenomKeyIssuePriv,
|
||||||
|
issue.signature);
|
||||||
if (GNUNET_SYSERR == (wrote = GNUNET_DISK_file_write (fh,
|
if (GNUNET_SYSERR == (wrote = GNUNET_DISK_file_write (fh,
|
||||||
&dki->issue.signature,
|
&dki->issue.signature,
|
||||||
wsize)))
|
wsize)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (wrote != wsize)
|
if (wrote != wsize)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (GNUNET_SYSERR == (wrote = GNUNET_DISK_file_write (fh,
|
if (GNUNET_SYSERR ==
|
||||||
priv_enc,
|
(wrote = GNUNET_DISK_file_write (fh,
|
||||||
priv_enc_size)))
|
priv_enc,
|
||||||
|
priv_enc_size)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if (wrote != priv_enc_size)
|
if (wrote != priv_enc_size)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -183,6 +182,14 @@ TALER_MINT_write_denom_key (const char *filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct DenomkeysIterateContext
|
||||||
|
{
|
||||||
|
const char *alias;
|
||||||
|
TALER_MINT_DenomkeyIterator it;
|
||||||
|
void *it_cls;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
denomkeys_iterate_keydir_iter (void *cls,
|
denomkeys_iterate_keydir_iter (void *cls,
|
||||||
const char *filename)
|
const char *filename)
|
||||||
@ -191,7 +198,9 @@ denomkeys_iterate_keydir_iter (void *cls,
|
|||||||
struct DenomkeysIterateContext *dic = cls;
|
struct DenomkeysIterateContext *dic = cls;
|
||||||
struct TALER_MINT_DenomKeyIssuePriv issue;
|
struct TALER_MINT_DenomKeyIssuePriv issue;
|
||||||
|
|
||||||
if (GNUNET_OK != TALER_MINT_read_denom_key (filename, &issue))
|
if (GNUNET_OK !=
|
||||||
|
TALER_MINT_read_denom_key (filename,
|
||||||
|
&issue))
|
||||||
{
|
{
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
|
||||||
"Invalid denomkey file: '%s'\n",
|
"Invalid denomkey file: '%s'\n",
|
||||||
@ -211,7 +220,9 @@ denomkeys_iterate_topdir_iter (void *cls,
|
|||||||
dic->alias = GNUNET_STRINGS_get_short_name (filename);
|
dic->alias = GNUNET_STRINGS_get_short_name (filename);
|
||||||
|
|
||||||
// FIXME: differentiate between error case and normal iteration abortion
|
// FIXME: differentiate between error case and normal iteration abortion
|
||||||
if (0 > GNUNET_DISK_directory_scan (filename, &denomkeys_iterate_keydir_iter, dic))
|
if (0 > GNUNET_DISK_directory_scan (filename,
|
||||||
|
&denomkeys_iterate_keydir_iter,
|
||||||
|
dic))
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of TALER
|
This file is part of TALER
|
||||||
Copyright (C) 2014 Christian Grothoff (and other contributing authors)
|
Copyright (C) 2014, 2015 Christian Grothoff (and other contributing authors)
|
||||||
|
|
||||||
TALER is free software; you can redistribute it and/or modify it under the
|
TALER is free software; you can redistribute it and/or modify it under the
|
||||||
terms of the GNU General Public License as published by the Free Software
|
terms of the GNU General Public License as published by the Free Software
|
||||||
|
Loading…
Reference in New Issue
Block a user