Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few memory leaks in libnvme #744

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/nvme/nbft.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ static int read_ssns(struct nbft_info *nbft,
verify(raw_ssns->structure_id == NBFT_DESC_SSNS,
"invalid ID in SSNS descriptor");

/* verify transport type */
verify(raw_ssns->trtype == NBFT_TRTYPE_TCP,
"invalid transport type in SSNS descriptor");

ssns = calloc(1, sizeof(*ssns));
if (!ssns)
return -ENOMEM;

ssns->index = le16_to_cpu(raw_ssns->index);

/* transport type */
verify(raw_ssns->trtype == NBFT_TRTYPE_TCP,
"invalid transport type in SSNS descriptor");
strncpy(ssns->transport, trtype_to_string(raw_ssns->trtype), sizeof(ssns->transport));

/* transport specific flags */
Expand Down Expand Up @@ -411,26 +411,29 @@ static int read_discovery(struct nbft_info *nbft,
struct nbft_discovery *raw_discovery,
struct nbft_info_discovery **d)
{
struct nbft_info_discovery *discovery;
struct nbft_info_discovery *discovery = NULL;
struct nbft_header *header = (struct nbft_header *)nbft->raw_nbft;
int r = -EINVAL;

if (!(raw_discovery->flags & NBFT_DISCOVERY_VALID))
return -EINVAL;
goto error;

verify(raw_discovery->structure_id == NBFT_DESC_DISCOVERY,
"invalid ID in discovery descriptor");

discovery = calloc(1, sizeof(struct nbft_info_discovery));
if (!discovery)
return -ENOMEM;
if (!discovery) {
r = -ENOMEM;
goto error;
}

discovery->index = raw_discovery->index;

if (get_heap_obj(raw_discovery, discovery_ctrl_addr_obj, 1, &discovery->uri))
return -EINVAL;
goto error;

if (get_heap_obj(raw_discovery, discovery_ctrl_nqn_obj, 1, &discovery->nqn))
return -EINVAL;
goto error;

discovery->hfi = hfi_from_index(nbft, raw_discovery->hfi_index);
if (raw_discovery->hfi_index && !discovery->hfi)
Expand All @@ -445,7 +448,12 @@ static int read_discovery(struct nbft_info *nbft,
nbft->filename, discovery->index);

*d = discovery;
return 0;
r = 0;

error:
if (r)
free(discovery);
return r;
}

static int read_security(struct nbft_info *nbft,
Expand Down