From 809dc4187ecc510e505979b2fb607fa6ad70a2cb Mon Sep 17 00:00:00 2001 From: Paul Luse Date: Tue, 17 Oct 2017 19:04:19 -0700 Subject: [PATCH] blobcli: fixup error handling in dump_imp_open_cb() Change-Id: Ia7feebd39a023642b94bedbab4da8f3b2f09b245 Signed-off-by: Paul Luse Reviewed-on: https://review.gerrithub.io/382904 Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- examples/blob/cli/blobcli.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/blob/cli/blobcli.c b/examples/blob/cli/blobcli.c index 7f96ed79a..5e7a8bdf7 100644 --- a/examples/blob/cli/blobcli.c +++ b/examples/blob/cli/blobcli.c @@ -683,8 +683,8 @@ dump_imp_open_cb(void *cb_arg, struct spdk_blob *blob, int bserrno) cli_context->buff = spdk_dma_malloc(cli_context->page_size, ALIGN_4K, NULL); if (cli_context->buff == NULL) { - unload_bs(cli_context, "Error in allocating memory", - -ENOMEM); + printf("Error in allocating memory\n"); + spdk_bs_md_close_blob(&cli_context->blob, close_cb, cli_context); return; } printf("Working"); @@ -692,6 +692,11 @@ dump_imp_open_cb(void *cb_arg, struct spdk_blob *blob, int bserrno) cli_context->page_count = 0; if (cli_context->action == CLI_DUMP) { cli_context->fp = fopen(cli_context->file, "w"); + if (cli_context->fp == NULL) { + printf("Error in opening file\n"); + spdk_bs_md_close_blob(&cli_context->blob, close_cb, cli_context); + return; + } /* read a page of data from the blob */ spdk_bs_io_read_blob(cli_context->blob, cli_context->channel, @@ -699,6 +704,11 @@ dump_imp_open_cb(void *cb_arg, struct spdk_blob *blob, int bserrno) NUM_PAGES, read_dump_cb, cli_context); } else { cli_context->fp = fopen(cli_context->file, "r"); + if (cli_context->fp == NULL) { + printf("Error in opening file\n"); + spdk_bs_md_close_blob(&cli_context->blob, close_cb, cli_context); + return; + } /* get the filesize then rewind read a page of data from file */ fseek(cli_context->fp, 0L, SEEK_END);