Skip to content

Commit

Permalink
Fix f_int leak in error path
Browse files Browse the repository at this point in the history
a memory leak was detected by valgrind:
==267184== 2,376 bytes in 1 blocks are definitely lost in loss record 2 of 2
==267184==    at 0x4C33B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==267184==    by 0x4E43342: allocate_fabric_internal (ibnetdisc.c:760)
==267184==    by 0x4E4353D: ibnd_discover_fabric (ibnetdisc.c:789)
==267184==    by 0x10A542: main (ibnetdiscover.c:1133)

Signed-off-by: Li Zhijian <[email protected]>
  • Loading branch information
zhijianli88 committed Jun 11, 2021
1 parent cd6b299 commit 4b49aa1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions libibnetdisc/ibnetdisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ ibnd_fabric_t *ibnd_discover_fabric(char * ca_name, int ca_port,
ibmad_port = mad_rpc_open_port(ca_name, ca_port, mc, nc);
if (!ibmad_port) {
IBND_ERROR("can't open MAD port (%s:%d)\n", ca_name, ca_port);
return (NULL);
goto error_int;
}
mad_rpc_set_timeout(ibmad_port, cfg->timeout_ms);
mad_rpc_set_retries(ibmad_port, cfg->retries);
Expand All @@ -810,13 +810,12 @@ ibnd_fabric_t *ibnd_discover_fabric(char * ca_name, int ca_port,
NULL, NULL, ibmad_port) < 0) {
IBND_ERROR("Failed to resolve self\n");
mad_rpc_close_port(ibmad_port);
return NULL;
goto error_int;
}
mad_rpc_close_port(ibmad_port);

if (smp_engine_init(&engine, ca_name, ca_port, &scan, &config)) {
free(f_int);
return (NULL);
goto error_int;
}

IBND_DEBUG("from %s\n", portid2str(from));
Expand All @@ -836,6 +835,8 @@ ibnd_fabric_t *ibnd_discover_fabric(char * ca_name, int ca_port,
error:
smp_engine_destroy(&engine);
ibnd_destroy_fabric(&f_int->fabric);
error_int:
free(f_int);
return NULL;
}

Expand Down

0 comments on commit 4b49aa1

Please sign in to comment.