Skip to content

Commit f96416c

Browse files
Colin Ian Kingdledford
authored andcommitted
RDMA/iwpm: fix memory leak on map_info
In the cases where iwpm_hash_bucket is NULL and where function get_mapinfo_hash_bucket returns NULL then the map_info is never added to hash_bucket_head and hence there is a leak of map_info. Fix this by nullifying hash_bucket_head and if that is null we know that that map_info was not added to hash_bucket_head and hence map_info should be free'd. Detected by CoverityScan, CID#1222481 ("Resource Leak") Fixes: 30dc5e6 ("RDMA/core: Add support for iWARP Port Mapper user space service") Signed-off-by: Colin Ian King <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 47a3968 commit f96416c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/infiniband/core/iwpm_util.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,
114114
struct sockaddr_storage *mapped_sockaddr,
115115
u8 nl_client)
116116
{
117-
struct hlist_head *hash_bucket_head;
117+
struct hlist_head *hash_bucket_head = NULL;
118118
struct iwpm_mapping_info *map_info;
119119
unsigned long flags;
120120
int ret = -EINVAL;
@@ -142,6 +142,9 @@ int iwpm_create_mapinfo(struct sockaddr_storage *local_sockaddr,
142142
}
143143
}
144144
spin_unlock_irqrestore(&iwpm_mapinfo_lock, flags);
145+
146+
if (!hash_bucket_head)
147+
kfree(map_info);
145148
return ret;
146149
}
147150

0 commit comments

Comments
 (0)