[cdatapack] fix memory handling for cdatapack

Summary:
`->index_table` is not heap-alloacted.  however, `->fanout_table` is and should be released.

Also added call to `close_datapack()` at the end of `cdatapack_dump.c`.

Depends on D3627122

Test Plan: valgrind is much happier now.

Reviewers: durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3631368

Signature: t1:3631368:1469741779:e0c4e5d59c7e73c8aa3507901df3005383f0d3f5
This commit is contained in:
Tony Tung 2016-08-01 14:11:16 -07:00
parent 705c0731b6
commit 20126b3bd8
3 changed files with 15 additions and 2 deletions

View File

@ -276,7 +276,11 @@ error_cleanup:
if (handle && handle->datafd != 0) {
close(handle->datafd);
}
free(handle->index_table);
if (handle != NULL) {
free(handle->fanout_table);
}
free(handle);
handle = NULL;
@ -293,7 +297,7 @@ void close_datapack(datapack_handle_t *handle) {
munmap(handle->data_mmap, handle->data_file_sz);
close(handle->indexfd);
close(handle->datafd);
free(handle->index_table);
free(handle->fanout_table);
free(handle);
}
@ -410,3 +414,8 @@ delta_chain_t *getdeltachain(
return delta_chain;
}
void freedeltachain(delta_chain_t *chain) {
free(chain->delta_chain_links);
free(chain);
}

View File

@ -87,6 +87,8 @@ extern delta_chain_t *getdeltachain(
const datapack_handle_t *handle,
uint8_t node[NODE_SZ]);
extern void freedeltachain(delta_chain_t *chain);
// this should really be private, but we need it for the cdatapack_dump tool.
extern const uint8_t *getdeltachainlink(
const uint8_t *ptr, delta_chain_link_t *link);

View File

@ -66,4 +66,6 @@ int main(int argc, char *argv[]) {
NODE_SZ * 2, node_buffer, NODE_SZ * 2, deltabase_buffer,
link.delta_sz);
}
close_datapack(handle);
}