Skip to contentSkip to conversation

libmpathpersist: fix resource leak in update_map_pr()

PATCH In review [email protected] 2 participants 2 messages Feb 2, 2023 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libmpathpersist: fix resource leak in update_map_pr()

From: Martin Wilck <[email protected]>

The "no available paths" case would leak the memory resp points to. Found by coverity.

Fixes 50e2c16 ("multipathd: handle no active paths in update_map_pr")
---
 libmpathpersist/mpath_persist_int.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
libmpathpersist/mpath_persist_int.c +8 -7
index 8b52b74..178c2f5 100644
@@ -733,7 +733,7 @@ int update_map_pr(struct multipath *mpp)
 	int noisy=0;
 	struct prin_resp *resp;
 	unsigned int i;
-	int ret, isFound;
+	int ret = MPATH_PR_OTHER, isFound;
 
 	if (!get_be64(mpp->reservation_key))
 	{
@@ -754,7 +754,7 @@ int update_map_pr(struct multipath *mpp)
 	{
 		condlog(0,"%s: No available paths to check pr status",
 			mpp->alias);
-		return MPATH_PR_OTHER;
+		goto out;
 	}
 	mpp->prflag = PRFLAG_UNSET;
 	ret = mpath_prin_activepath(mpp, MPATH_PRIN_RKEY_SA, resp, noisy);
@@ -762,15 +762,15 @@ int update_map_pr(struct multipath *mpp)
 	if (ret != MPATH_PR_SUCCESS )
 	{
 		condlog(0,"%s : pr in read keys service action failed Error=%d", mpp->alias, ret);
-		free(resp);
-		return  ret;
+		goto out;
 	}
 
+	ret = MPATH_PR_SUCCESS;
+
 	if (resp->prin_descriptor.prin_readkeys.additional_length == 0 )
 	{
 		condlog(3,"%s: No key found. Device may not be registered. ", mpp->alias);
-		free(resp);
-		return MPATH_PR_SUCCESS;
+		goto out;
 	}
 
 	condlog(2, "%s: Multipath  reservation_key: 0x%" PRIx64 " ", mpp->alias,
@@ -795,6 +795,7 @@ int update_map_pr(struct multipath *mpp)
 		condlog(2, "%s: prflag flag set.", mpp->alias );
 	}
 
+out:
 	free(resp);
-	return MPATH_PR_SUCCESS;
+	return ret;
 }
Signature · 6 lines
2.39.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Thu, Feb 02, 2023 at 09:42:20AM +0100, [email protected] wrote:

From: Martin Wilck <[email protected]>

The "no available paths" case would leak the memory resp points to. Found by coverity.

Fixes 50e2c16 ("multipathd: handle no active paths in update_map_pr")

Oops.

Quoted 59 lines
---
 libmpathpersist/mpath_persist_int.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
libmpathpersist/mpath_persist_int.c +8 -7
index 8b52b74..178c2f5 100644
@@ -733,7 +733,7 @@ int update_map_pr(struct multipath *mpp)
 	int noisy=0;
 	struct prin_resp *resp;
 	unsigned int i;
-	int ret, isFound;
+	int ret = MPATH_PR_OTHER, isFound;
 
 	if (!get_be64(mpp->reservation_key))
 	{
@@ -754,7 +754,7 @@ int update_map_pr(struct multipath *mpp)
 	{
 		condlog(0,"%s: No available paths to check pr status",
 			mpp->alias);
-		return MPATH_PR_OTHER;
+		goto out;
 	}
 	mpp->prflag = PRFLAG_UNSET;
 	ret = mpath_prin_activepath(mpp, MPATH_PRIN_RKEY_SA, resp, noisy);
@@ -762,15 +762,15 @@ int update_map_pr(struct multipath *mpp)
 	if (ret != MPATH_PR_SUCCESS )
 	{
 		condlog(0,"%s : pr in read keys service action failed Error=%d", mpp->alias, ret);
-		free(resp);
-		return  ret;
+		goto out;
 	}
 
+	ret = MPATH_PR_SUCCESS;
+
 	if (resp->prin_descriptor.prin_readkeys.additional_length == 0 )
 	{
 		condlog(3,"%s: No key found. Device may not be registered. ", mpp->alias);
-		free(resp);
-		return MPATH_PR_SUCCESS;
+		goto out;
 	}
 
 	condlog(2, "%s: Multipath  reservation_key: 0x%" PRIx64 " ", mpp->alias,
@@ -795,6 +795,7 @@ int update_map_pr(struct multipath *mpp)
 		condlog(2, "%s: prflag flag set.", mpp->alias );
 	}
 
+out:
 	free(resp);
-	return MPATH_PR_SUCCESS;
+	return ret;
 }
Signature · 1 line
2.39.1

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel