From f3ef436c8e720da4a2169b71f0d3ee68abce5420 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Tue, 12 Apr 2016 00:04:21 +0300 Subject: [PATCH] Fix memory leak in Basic http-auth --- http-auth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/http-auth.c b/http-auth.c index d37d655..08234c5 100644 --- a/http-auth.c +++ b/http-auth.c @@ -32,15 +32,15 @@ char* basic_authentication_encode(const char *user, const char *passwd) { /* prepare the user:pass key pair */ int pair_len = strlen(user) + 1 + strlen(passwd); - char *pair_ptr = calloc(pair_len + 1, 1); + char pair[pair_len + 1]; - sprintf(pair_ptr, "%s:%s", user, passwd); + sprintf(pair, "%s:%s", user, passwd); /* calculate the final string length */ int basic_len = BASE64_SIZE(pair_len); char *basic_ptr = calloc(basic_len + 1, 1); - if (!base64_encode(basic_ptr, basic_len, (const uint8_t*)pair_ptr, pair_len)) + if (!base64_encode(basic_ptr, basic_len, (const uint8_t*)pair, pair_len)) return NULL; return basic_ptr;