fix lots of memory leaks
This commit is contained in:
24
src/image.c
24
src/image.c
@@ -349,20 +349,23 @@ enum ec3_status ec3_image_ioctx_open(
|
||||
b_path *image_path = b_path_create_from_cstr(path);
|
||||
b_file_info image_info;
|
||||
enum b_status status = b_path_stat(image_path, &image_info);
|
||||
enum ec3_status status2 = EC3_ERR_NO_ENTRY;
|
||||
|
||||
if ((status == B_ERR_NO_ENTRY) && (mode & EC3_IMAGE_IO_WRITE)) {
|
||||
return open_image_create(image_path, mode, param, out);
|
||||
status2 = open_image_create(image_path, mode, param, out);
|
||||
}
|
||||
|
||||
if ((status == B_SUCCESS) && (mode & EC3_IMAGE_IO_WRITE)) {
|
||||
return open_image_rw(image_path, mode, out);
|
||||
status2 = open_image_rw(image_path, mode, out);
|
||||
}
|
||||
|
||||
if ((status == B_SUCCESS) && (mode & EC3_IMAGE_IO_READ)) {
|
||||
return open_image_ro(image_path, mode, out);
|
||||
status2 = open_image_ro(image_path, mode, out);
|
||||
}
|
||||
|
||||
return EC3_ERR_NO_ENTRY;
|
||||
b_path_release(image_path);
|
||||
|
||||
return status2;
|
||||
}
|
||||
|
||||
static void destroy_image_ioctx(struct ec3_image_ioctx *image)
|
||||
@@ -507,6 +510,19 @@ enum ec3_status ec3_image_ioctx_close(struct ec3_image_ioctx *image)
|
||||
}
|
||||
}
|
||||
|
||||
b_btree_iterator it;
|
||||
b_btree_iterator_begin(&image->io_opened_tags, &it);
|
||||
while (b_btree_iterator_is_valid(&it)) {
|
||||
struct ec3_tag_ioctx *tag
|
||||
= b_unbox(struct ec3_tag_ioctx, it.node, io_node);
|
||||
b_btree_iterator_erase(&it);
|
||||
|
||||
/* disable write access so that ec3_tag_ioctx_close will
|
||||
* actually destroy the ioctx */
|
||||
tag->io_mode &= ~EC3_TAG_IO_WRITE;
|
||||
ec3_tag_ioctx_close(tag);
|
||||
}
|
||||
|
||||
shadow_image_finish(image, &shadow);
|
||||
destroy_image_ioctx(image);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user