Don't access freed memory
Instead of accessing memory of a freed IO, redo size calculations
@@ -332,6 +332,8 @@ int raw_dynamic_update(ocf_cache_t cache,
* RAM DYNAMIC Implementation - Load all
*/
#define RAW_DYNAMIC_LOAD_PAGES 128
+#define metadata_io_size(__i_page, __pages_total) \
+ OCF_MIN(RAW_DYNAMIC_LOAD_PAGES, (__pages_total -__i_page))
struct raw_dynamic_load_all_context {
struct ocf_metadata_raw *raw;
@@ -389,8 +391,7 @@ static int raw_dynamic_load_all_read(struct ocf_request *req)
uint64_t count;
int result;
- count = OCF_MIN(RAW_DYNAMIC_LOAD_PAGES,
- raw->ssd_pages - context->i_page);
+ count = metadata_io_size(context->i_page, raw->ssd_pages);
/* Allocate IO */
context->io = ocf_new_cache_io(context->cache, req->io_queue,
@@ -428,7 +429,7 @@ static int raw_dynamic_load_all_update(struct ocf_request *req)
struct raw_dynamic_load_all_context *context = req->priv;
struct ocf_metadata_raw *raw = context->raw;
ocf_cache_t cache = context->cache;
- uint64_t count = BYTES_TO_PAGES(context->io->bytes);
+ uint64_t count = metadata_io_size(context->i_page, raw->ssd_pages);
int result = 0;
/* Reset head of data buffer */
