Skip to content
Snippets Groups Projects
Commit 0afc68cc authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Fix memory leak

parent ee9360b4
No related branches found
No related tags found
No related merge requests found
......@@ -258,22 +258,31 @@ int32_t base32hex_encode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out)
{
int32_t ret;
uint32_t out_len = ((in_len + 4) / 5) * 8;
// Checking inputs.
// Check inputs.
if (in_len > MAX_BIN_DATA_LEN) {
return -1;
}
// Allocating output buffer.
// Allocate output buffer.
*out = malloc(out_len);
if (*out == NULL) {
return -1;
}
// Encoding data.
return base32hex_encode(in, in_len, *out, out_len);
// Encode data.
ret = base32hex_encode(in, in_len, *out, out_len);
// Check return.
if (ret < 0) {
free(out);
return -1;
} else {
return ret;
}
}
int32_t base32hex_decode(const uint8_t *in,
......
......@@ -256,16 +256,25 @@ int32_t base64_decode_alloc(const uint8_t *in,
const uint32_t in_len,
uint8_t **out)
{
int32_t ret;
uint32_t out_len = ((in_len + 3) / 4) * 3;
*out = malloc(out_len);
// Allocating output buffer.
// Allocate output buffer.
if (*out == NULL) {
return -1;
}
// Decoding data.
return base64_decode(in, in_len, *out, out_len);
// Decode data.
ret = base64_decode(in, in_len, *out, out_len);
// Check return.
if (ret < 0) {
free(out);
return -1;
} else {
return ret;
}
}
......@@ -1501,8 +1501,8 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
if (((b32_ret = base32hex_encode_alloc(((uint8_t *)
rdata_item_data(&(nsec3_rrset->rdata->items[4]))) + 1,
rdata_item_size(&nsec3_rrset->rdata->items[4]) - 1,
&next_dname_decoded)) <= 0) ||
(next_dname_decoded == NULL)) {
&next_dname_decoded)) < 0))
{
fprintf(stderr, "Could not encode base32 string!\n");
err_handler_handle_error(handler, last_nsec3_node,
ZC_ERR_NSEC3_RDATA_CHAIN);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment