[Skiboot] [PATCH 1/3] libflash/ipmi-hiomap: Cleanup allocation on init failure

Andrew Jeffery andrew at aj.id.au
Wed Oct 31 16:24:11 AEDT 2018


Previously we were leaking the memory pointed by ctx if an IPMI error
occurred during protocol initialisation. Make sure we free the memory if
an error occurs.

Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 libflash/ipmi-hiomap.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libflash/ipmi-hiomap.c b/libflash/ipmi-hiomap.c
index 5300daefa9d2..a7a6215bf901 100644
--- a/libflash/ipmi-hiomap.c
+++ b/libflash/ipmi-hiomap.c
@@ -813,25 +813,28 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
 
 	rc = ipmi_sel_register(CMD_OP_HIOMAP_EVENT, hiomap_event, ctx);
 	if (rc < 0)
-		return rc;
+		goto err;
 
 	/* Ack all pending ack-able events to avoid spurious failures */
 	if (!hiomap_ack(ctx, HIOMAP_E_ACK_MASK)) {
 		prlog(PR_DEBUG, "Failed to ack events: 0x%x\n",
 		      HIOMAP_E_ACK_MASK);
-		return FLASH_ERR_AGAIN;
+		rc = FLASH_ERR_AGAIN;
+		goto err;
 	}
 
 	/* Negotiate protocol behaviour */
 	if (!hiomap_get_info(ctx)) {
 		prerror("Failed to get hiomap parameters\n");
-		return FLASH_ERR_DEVICE_GONE;
+		rc = FLASH_ERR_DEVICE_GONE;
+		goto err;
 	}
 
 	/* Grab the flash parameters */
 	if (!hiomap_get_flash_info(ctx)) {
 		prerror("Failed to get flash parameters\n");
-		return FLASH_ERR_DEVICE_GONE;
+		rc = FLASH_ERR_DEVICE_GONE;
+		goto err;
 	}
 
 	prlog(PR_NOTICE, "Negotiated hiomap protocol v%u\n", ctx->version);
@@ -847,6 +850,11 @@ int ipmi_hiomap_init(struct blocklevel_device **bl)
 	*bl = &(ctx->bl);
 
 	return 0;
+
+err:
+	free(ctx);
+
+	return rc;
 }
 
 void ipmi_hiomap_exit(struct blocklevel_device *bl)
-- 
2.17.1



More information about the Skiboot mailing list