From: Danny Al-Gaaf Date: Tue, 22 Sep 2015 21:35:32 +0000 (+0200) Subject: test_crc32c.cc: close memory leak, free 'b' after malloc X-Git-Tag: v10.0.4~86^2~29 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=91279dfbb48d0680a4ea9a61a1e09ea369348da7;p=ceph.git test_crc32c.cc: close memory leak, free 'b' after malloc Signed-off-by: Danny Al-Gaaf --- diff --git a/src/test/common/test_crc32c.cc b/src/test/common/test_crc32c.cc index a31161620c92..54200b3a0dba 100644 --- a/src/test/common/test_crc32c.cc +++ b/src/test/common/test_crc32c.cc @@ -162,14 +162,15 @@ static uint32_t crc_check_table[] = { TEST(Crc32c, Range) { int len = sizeof(crc_check_table) / sizeof(crc_check_table[0]); - const char *b = (const char *)malloc(len); - memset((void *)b, 1, len); + unsigned char *b = (unsigned char *)malloc(len); + memset(b, 1, len); uint32_t crc = 0; uint32_t *check = crc_check_table; for (int i = 0 ; i < len; i++, check++) { - crc = ceph_crc32c(crc, (unsigned char *)b+i, len-i); + crc = ceph_crc32c(crc, b+i, len-i); ASSERT_EQ(crc, *check); } + free(b); } static uint32_t crc_zero_check_table[] = { @@ -241,15 +242,16 @@ static uint32_t crc_zero_check_table[] = { TEST(Crc32c, RangeZero) { int len = sizeof(crc_zero_check_table) / sizeof(crc_zero_check_table[0]); - const char *b = (const char *)malloc(len); - memset((void *)b, 0, len); + unsigned char *b = (unsigned char *)malloc(len); + memset(b, 0, len); uint32_t crc = 1; /* when checking zero buffer we want to start with a non zero crc, otherwise all the results are going to be zero */ uint32_t *check = crc_zero_check_table; for (int i = 0 ; i < len; i++, check++) { - crc = ceph_crc32c(crc, (unsigned char *)b+i, len-i); + crc = ceph_crc32c(crc, b+i, len-i); ASSERT_EQ(crc, *check); } + free(b); } TEST(Crc32c, RangeNull) {