Skip to content

ibdiag_sa: Fix memory leak in sa_query() #1602

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

Merged
merged 1 commit into from
Apr 27, 2025
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
10 changes: 8 additions & 2 deletions infiniband-diags/ibdiag_sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int sa_query(struct sa_handle * h, uint8_t method,
struct sa_query_result *result)
{
ib_rpc_t rpc;
void *umad, *mad;
void *umad, *mad, *new_umad;
int ret, offset, len = 256;

memset(&rpc, 0, sizeof(rpc));
Expand Down Expand Up @@ -139,7 +139,13 @@ int sa_query(struct sa_handle * h, uint8_t method,
ret = umad_recv(h->fd, umad, &len, ibd_timeout);
if (ret < 0) {
if (errno == ENOSPC) {
umad = realloc(umad, umad_size() + len);
new_umad = realloc(umad, umad_size() + len);
if (!new_umad) {
IBWARN("Failed to reallocate memory for umad: %s\n", strerror(errno));
free(umad);
return (-ret);
}
umad = new_umad;
goto recv_mad;
}
IBWARN("umad_recv failed: attr 0x%x: %s\n", attr,
Expand Down