From 57d93c9ecbba2c45e7f86410518e2399bf01a846 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 29 May 2018 17:41:23 +0900 Subject: [PATCH] blobstore: Hold the original buffer to free it when realloc() is failed Change-Id: I1f2c62b2607fb6efb82c9de59244ba3e32fa67ca Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/412753 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp Reviewed-by: Ben Walker --- lib/blob/blobstore.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 29a9dca541..a946cc7628 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -1277,6 +1277,7 @@ _spdk_blob_persist_start(struct spdk_blob_persist_ctx *ctx) struct spdk_blob_store *bs = blob->bs; uint64_t i; uint32_t page_num; + void *tmp; int rc; if (blob->active.num_pages == 0) { @@ -1300,12 +1301,12 @@ _spdk_blob_persist_start(struct spdk_blob_persist_ctx *ctx) assert(blob->active.num_pages >= 1); /* Resize the cache of page indices */ - blob->active.pages = realloc(blob->active.pages, - blob->active.num_pages * sizeof(*blob->active.pages)); - if (!blob->active.pages) { + tmp = realloc(blob->active.pages, blob->active.num_pages * sizeof(*blob->active.pages)); + if (!tmp) { _spdk_blob_persist_complete(seq, ctx, -ENOMEM); return; } + blob->active.pages = tmp; /* Assign this metadata to pages. This requires two passes - * one to verify that there are enough pages and a second