From 4fc355ba68fa2708a9ff9689e4e1a22489229bb2 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 15 Mar 2016 14:31:53 -0700 Subject: [PATCH] examples/nvme/reserve: add malloc checks and frees Change-Id: I576ac640c3c8a94237e5437e7e7f029d8526c071 Signed-off-by: Daniel Verkamp --- examples/nvme/reserve/reservation.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/nvme/reserve/reservation.c b/examples/nvme/reserve/reservation.c index 102f84b40..60fe675af 100644 --- a/examples/nvme/reserve/reservation.c +++ b/examples/nvme/reserve/reservation.c @@ -116,10 +116,15 @@ get_host_identifier(struct spdk_nvme_ctrlr *ctrlr) outstanding_commands = 0; host_id = rte_malloc(NULL, 8, 0); + if (host_id == NULL) { + fprintf(stderr, "host_id allocation failed\n"); + return -1; + } ret = spdk_nvme_ctrlr_cmd_admin_raw(ctrlr, &cmd, host_id, 8, get_feature_completion, &features[SPDK_NVME_FEAT_HOST_IDENTIFIER]); if (ret) { fprintf(stdout, "Get Feature: Failed\n"); + rte_free(host_id); return -1; } @@ -133,6 +138,7 @@ get_host_identifier(struct spdk_nvme_ctrlr *ctrlr) fprintf(stdout, "Get Feature: Host Identifier 0x%"PRIx64"\n", *host_id); } + rte_free(host_id); return 0; } @@ -147,6 +153,10 @@ set_host_identifier(struct spdk_nvme_ctrlr *ctrlr) cmd.cdw10 = SPDK_NVME_FEAT_HOST_IDENTIFIER; host_id = rte_malloc(NULL, 8, 0); + if (host_id == NULL) { + fprintf(stderr, "host_id allocation failed\n"); + return -1; + } *host_id = HOST_ID; outstanding_commands = 0;