aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-11-16 00:52:49 +0100
committerGravatar Tom Willemse2013-11-16 00:52:49 +0100
commit9b4461479e0f038391367e5afca1735b7e11c788 (patch)
treea2a5320c9752a65d461c0d68eb86797e963104fa
parentf6a9356dc34a647aa0777675b79f71247bc6a141 (diff)
downloadlibdispass-9b4461479e0f038391367e5afca1735b7e11c788.tar.gz
libdispass-9b4461479e0f038391367e5afca1735b7e11c788.zip
Fix memory leak
-rw-r--r--sha1.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/sha1.c b/sha1.c
index 2a8fda1..7e988b2 100644
--- a/sha1.c
+++ b/sha1.c
@@ -12,6 +12,7 @@ base64encode(const void *data, int len)
{ /* Copied from http://stackoverflow.com/a/16511093/459915 */
BIO *b64_bio, *mem_bio;
BUF_MEM *mem_bio_mem_ptr;
+ char *ret;
b64_bio = BIO_new(BIO_f_base64());
mem_bio = BIO_new(BIO_s_mem());
@@ -26,8 +27,11 @@ base64encode(const void *data, int len)
BIO_free_all(b64_bio);
(*mem_bio_mem_ptr).data[(*mem_bio_mem_ptr).length] = '\0';
+ ret = calloc((*mem_bio_mem_ptr).length, sizeof(char));
+ strncpy(ret, (*mem_bio_mem_ptr).data, (*mem_bio_mem_ptr).length);
+ BUF_MEM_free(mem_bio_mem_ptr);
- return (*mem_bio_mem_ptr).data;
+ return ret;
}
void
@@ -89,9 +93,22 @@ dispass2(char *label, char *password, int len, int seqno)
int main(int argc, char *argv[])
{
- printf("%s\n", dispass1("test", "qqqqqqqq", 30, 0));
- printf("%s\n", dispass1("test2", "qqqqqqqq", 50, 0));
- printf("%s\n", dispass2("test", "qqqqqqqq", 30, 1));
- printf("%s\n", dispass2("test2", "qqqqqqqq", 50, 10));
+ char *test1, *test2, *test3, *test4;
+
+ test1 = dispass1("test", "qqqqqqqq", 30, 0);
+ test2 = dispass1("test2", "qqqqqqqq", 50, 0);
+ test3 = dispass2("test", "qqqqqqqq", 30, 1);
+ test4 = dispass2("test2", "qqqqqqqq", 50, 10);
+
+ printf("%s\n", test1);
+ printf("%s\n", test2);
+ printf("%s\n", test3);
+ printf("%s\n", test4);
+
+ free(test1);
+ free(test2);
+ free(test3);
+ free(test4);
+
return 0;
}