diff --git a/Makefile.am b/Makefile.am index 520a0185..7897d87f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ core_sources = \ src/command/commands.h src/command/commands.c \ src/command/history.h src/tools/parser.c \ src/tools/parser.h \ + src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ src/tools/history.c src/tools/history.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ @@ -48,6 +49,7 @@ tests_sources = \ src/command/commands.h src/command/commands.c \ src/command/history.h src/tools/parser.c \ src/tools/parser.h \ + src/tools/p_sha1.h src/tools/p_sha1.c \ src/tools/autocomplete.c src/tools/autocomplete.h \ src/tools/history.c src/tools/history.h \ src/tools/tinyurl.c src/tools/tinyurl.h \ diff --git a/prof.supp b/prof.supp new file mode 100644 index 00000000..8a33cdbf --- /dev/null +++ b/prof.supp @@ -0,0 +1,19 @@ +{ + _dl_init + Memcheck:Leak + ... + fun:_dl_init + obj:/lib/x86_64-linux-gnu/ld-2.17.so + ... +} + +{ + otrl_init + Memcheck:Leak + ... + fun:_otr_init + fun:_init + fun:prof_run + ... +} + diff --git a/src/common.c b/src/common.c index 65658aec..43358940 100644 --- a/src/common.c +++ b/src/common.c @@ -33,7 +33,7 @@ #include #include -#include "tools/sha1.h" +#include "tools/p_sha1.h" #include "log.h" #include "common.h" @@ -416,16 +416,16 @@ generate_unique_id(char *prefix) } char * -sha1_hash(char *str) +p_sha1_hash(char *str) { - SHA1_CTX ctx; + P_SHA1_CTX ctx; uint8_t digest[20]; uint8_t *input = (uint8_t*)malloc(strlen(str) + 1); memcpy(input, str, strlen(str) + 1); - SHA1_Init(&ctx); - SHA1_Update(&ctx, input, strlen(str)); - SHA1_Final(&ctx, digest); + P_SHA1_Init(&ctx); + P_SHA1_Update(&ctx, input, strlen(str)); + P_SHA1_Final(&ctx, digest); free(input); return g_base64_encode(digest, sizeof(digest)); diff --git a/src/common.h b/src/common.h index d22992fd..7b98a2bc 100644 --- a/src/common.h +++ b/src/common.h @@ -98,7 +98,7 @@ const char * string_from_resource_presence(resource_presence_t presence); resource_presence_t resource_presence_from_string(const char * const str); contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence); -char * sha1_hash(char *str); +char * p_sha1_hash(char *str); char * generate_unique_id(char *prefix); int cmp_win_num(gconstpointer a, gconstpointer b); diff --git a/src/config/preferences.c b/src/config/preferences.c index 34e8a704..4bb0ed3d 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -373,8 +373,9 @@ static void _save_prefs(void) { gsize g_data_size; - char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); + gchar *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL); g_file_set_contents(prefs_loc, g_prefs_data, g_data_size, NULL); + g_free(g_prefs_data); } static gchar * diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index f6d57e23..7aaf2ab5 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -162,6 +162,9 @@ autocomplete_complete(Autocomplete ac, gchar *search_str) // first search attempt if (ac->last_found == NULL) { + if (ac->search_str != NULL) { + FREE_SET_NULL(ac->search_str); + } ac->search_str = strdup(search_str); found = _search_from(ac, ac->items); return found; diff --git a/src/tools/sha1.c b/src/tools/p_sha1.c similarity index 87% rename from src/tools/sha1.c rename to src/tools/p_sha1.c index 69ad2a6e..7c059c97 100644 --- a/src/tools/sha1.c +++ b/src/tools/p_sha1.c @@ -14,10 +14,10 @@ Still 100% Public Domain Corrected a problem which generated improper hash values on 16 bit machines Routine SHA1Update changed from - void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned int + void SHA1Update(P_SHA1_CTX* context, unsigned char* data, unsigned int len) to - void SHA1Update(SHA1_CTX* context, unsigned char* data, unsigned + void SHA1Update(P_SHA1_CTX* context, unsigned char* data, unsigned long len) The 'len' parameter was declared an int which works fine on 32 bit machines. @@ -99,9 +99,9 @@ A million repetitions of "a" #include #endif -#include "sha1.h" +#include "p_sha1.h" -void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]); +void P_SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]); #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) @@ -126,7 +126,7 @@ void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]); #ifdef VERBOSE /* SAK */ -void SHAPrintContext(SHA1_CTX *context, char *msg){ +void SHAPrintContext(P_P_SHA1_CTX *context, char *msg){ printf("%s (%d,%d) %x %x %x %x %x\n", msg, context->count[0], context->count[1], @@ -139,7 +139,7 @@ void SHAPrintContext(SHA1_CTX *context, char *msg){ #endif /* VERBOSE */ /* Hash a single 512-bit block. This is the core of the algorithm. */ -void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]) +void P_SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]) { uint32_t a, b, c, d, e; typedef union { @@ -198,7 +198,7 @@ void SHA1_Transform(uint32_t state[5], const uint8_t buffer[64]) /* SHA1Init - Initialize new context */ -void SHA1_Init(SHA1_CTX* context) +void P_SHA1_Init(P_SHA1_CTX* context) { /* SHA1 initialization constants */ context->state[0] = 0x67452301; @@ -211,7 +211,7 @@ void SHA1_Init(SHA1_CTX* context) /* Run your data through this. */ -void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len) +void P_SHA1_Update(P_SHA1_CTX* context, const uint8_t* data, const size_t len) { size_t i, j; @@ -224,9 +224,9 @@ void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len) context->count[1] += (len >> 29); if ((j + len) > 63) { memcpy(&context->buffer[j], data, (i = 64-j)); - SHA1_Transform(context->state, context->buffer); + P_SHA1_Transform(context->state, context->buffer); for ( ; i + 63 < len; i += 64) { - SHA1_Transform(context->state, data + i); + P_SHA1_Transform(context->state, data + i); } j = 0; } @@ -240,7 +240,7 @@ void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len) /* Add padding and return the message digest. */ -void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]) +void P_SHA1_Final(P_SHA1_CTX* context, uint8_t digest[P_SHA1_DIGEST_SIZE]) { uint32_t i; uint8_t finalcount[8]; @@ -249,12 +249,12 @@ void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]) finalcount[i] = (unsigned char)((context->count[(i >= 4 ? 0 : 1)] >> ((3-(i & 3)) * 8) ) & 255); /* Endian independent */ } - SHA1_Update(context, (uint8_t *)"\200", 1); + P_SHA1_Update(context, (uint8_t *)"\200", 1); while ((context->count[0] & 504) != 448) { - SHA1_Update(context, (uint8_t *)"\0", 1); + P_SHA1_Update(context, (uint8_t *)"\0", 1); } - SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */ - for (i = 0; i < SHA1_DIGEST_SIZE; i++) { + P_SHA1_Update(context, finalcount, 8); /* Should cause a SHA1_Transform() */ + for (i = 0; i < P_SHA1_DIGEST_SIZE; i++) { digest[i] = (uint8_t) ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); } @@ -267,7 +267,7 @@ void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]) memset(finalcount, 0, 8); /* SWR */ #ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ - SHA1_Transform(context->state, context->buffer); + P_SHA1_Transform(context->state, context->buffer); #endif } @@ -277,8 +277,8 @@ void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]) int main(int argc, char** argv) { int i, j; -SHA1_CTX context; -unsigned char digest[SHA1_DIGEST_SIZE], buffer[16384]; +P_SHA1_CTX context; +unsigned char digest[P_SHA1_DIGEST_SIZE], buffer[16384]; FILE* file; if (argc > 2) { @@ -303,7 +303,7 @@ FILE* file; } SHA1_Final(&context, digest); fclose(file); - for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) { + for (i = 0; i < P_SHA1_DIGEST_SIZE/4; i++) { for (j = 0; j < 4; j++) { printf("%02X", digest[i*4+j]); } @@ -327,12 +327,12 @@ static char *test_results[] = { "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1", "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F"}; -void digest_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], char *output) +void digest_to_hex(const uint8_t digest[P_SHA1_DIGEST_SIZE], char *output) { int i,j; char *c = output; - for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) { + for (i = 0; i < P_SHA1_DIGEST_SIZE/4; i++) { for (j = 0; j < 4; j++) { sprintf(c,"%02X", digest[i*4+j]); c += 2; @@ -346,16 +346,16 @@ void digest_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], char *output) int main(int argc, char** argv) { int k; - SHA1_CTX context; + P_SHA1_CTX context; uint8_t digest[20]; char output[80]; fprintf(stdout, "verifying SHA-1 implementation... "); for (k = 0; k < 2; k++){ - SHA1_Init(&context); - SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k])); - SHA1_Final(&context, digest); + P_SHA1_Init(&context); + P_SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k])); + P_SHA1_Final(&context, digest); digest_to_hex(digest, output); if (strcmp(output, test_results[k])) { @@ -367,10 +367,10 @@ int main(int argc, char** argv) } } /* million 'a' vector we feed separately */ - SHA1_Init(&context); + P_SHA1_Init(&context); for (k = 0; k < 1000000; k++) - SHA1_Update(&context, (uint8_t*)"a", 1); - SHA1_Final(&context, digest); + P_SHA1_Update(&context, (uint8_t*)"a", 1); + P_SHA1_Final(&context, digest); digest_to_hex(digest, output); if (strcmp(output, test_results[2])) { fprintf(stdout, "FAIL\n"); diff --git a/src/tools/sha1.h b/src/tools/p_sha1.h similarity index 50% rename from src/tools/sha1.h rename to src/tools/p_sha1.h index b637f662..75443b01 100644 --- a/src/tools/sha1.h +++ b/src/tools/p_sha1.h @@ -5,8 +5,8 @@ * SHA-1 hash API. */ -#ifndef __SHA1_H -#define __SHA1_H +#ifndef __P_SHA1_H +#define __P_SHA1_H #ifdef __cplusplus extern "C" { @@ -16,16 +16,16 @@ typedef struct { uint32_t state[5]; uint32_t count[2]; uint8_t buffer[64]; -} SHA1_CTX; +} P_SHA1_CTX; -#define SHA1_DIGEST_SIZE 20 +#define P_SHA1_DIGEST_SIZE 20 -void SHA1_Init(SHA1_CTX* context); -void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len); -void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]); +void P_SHA1_Init(P_SHA1_CTX* context); +void P_SHA1_Update(P_SHA1_CTX* context, const uint8_t* data, const size_t len); +void P_SHA1_Final(P_SHA1_CTX* context, uint8_t digest[P_SHA1_DIGEST_SIZE]); #ifdef __cplusplus } #endif -#endif /* __SHA1_H */ +#endif /* __P_SHA1_H */ diff --git a/src/ui/windows.c b/src/ui/windows.c index d7d3da5d..556e297a 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -305,11 +305,14 @@ wins_xmlconsole_exists(void) while (curr != NULL) { ProfWin *window = curr->data; - if (window->type == WIN_XML) + if (window->type == WIN_XML) { + g_list_free(values); return TRUE; + } curr = g_list_next(curr); } + g_list_free(values); return FALSE; } diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index 4c18faa4..801ec135 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -202,7 +202,7 @@ caps_create_sha1_str(xmpp_stanza_t * const query) curr = g_slist_next(curr); } - char *result = sha1_hash(s->str); + char *result = p_sha1_hash(s->str); g_string_free(s, TRUE); g_slist_free_full(identities, g_free);