From ecbceac3414bf851d166e8ce7dceaf1dae12bb08 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 9 Feb 2014 00:59:03 -0500 Subject: Fixed memory leaks and removed repeated code --- other/bootstrap_serverdaemon/tox_bootstrap_daemon.c | 5 +++-- other/fun/sign.c | 15 ++------------- 2 files changed, 5 insertions(+), 15 deletions(-) (limited to 'other') diff --git a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c index f2c54bb1..7f1f652c 100644 --- a/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/tox_bootstrap_daemon.c @@ -266,8 +266,9 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } - const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), - hex_string_to_bin((char *)bs_public_key)); + uint8_t *bs_public_key_bin = hex_string_to_bin((char *)bs_public_key); + const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), bs_public_key_bin); + free(bs_public_key_bin); if (!address_resolved) { syslog(LOG_WARNING, "Bootstrap server #%d: Invalid '%s': %s. Skipping the server.\n", i, NAME_ADDRESS, bs_address); diff --git a/other/fun/sign.c b/other/fun/sign.c index 423d974a..eaea9d6a 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -17,19 +17,7 @@ */ #include #include - -unsigned char *hex_string_to_bin(char hex_string[]) -{ - size_t len = strlen(hex_string); - unsigned char *val = malloc(len); - char *pos = hex_string; - int i; - - for (i = 0; i < len; ++i, pos += 2) - sscanf(pos, "%2hhx", &val[i]); - - return val; -} +#include "../../testing/misc_tools.c" // hex_string_to_bin int load_file(char *filename, char **result) { @@ -90,6 +78,7 @@ int main(int argc, char *argv[]) unsigned long long smlen; char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); crypto_sign_ed25519(sm, &smlen, data, size, secret_key); + free(secret_key); if (smlen - size != crypto_sign_ed25519_BYTES) goto fail; -- cgit v1.2.3