Skip to content

Commit

Permalink
bmi_port: Fix memory leak and incorrect return type (#1061)
Browse files Browse the repository at this point in the history
* bmi_port: fix incorrect return type

The function delete_port() is intended to have void return type, not
pointer.

Reported-by: cppcheck version 2.6
Signed-off-by: Radostin Stoyanov <[email protected]>

* bmi_port: fix memory leak

Reported-by: cppcheck version 2.6
Signed-off-by: Radostin Stoyanov <[email protected]>
  • Loading branch information
rst0git authored Dec 14, 2021
1 parent 1678f33 commit 779a19b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/BMI/bmi_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static inline bmi_port_t *insert_port(bmi_port_mgr_t *port_mgr, int port_num) {
return &port_mgr->ports[a];
}

static inline void *delete_port(bmi_port_mgr_t *port_mgr, bmi_port_t *port) {
static inline void delete_port(bmi_port_mgr_t *port_mgr, bmi_port_t *port) {
int idx = port - port_mgr->ports;
size_t size = (port_mgr->port_count - idx - 1) * sizeof(*port_mgr->ports);
memmove(port, port + 1, size);
Expand Down Expand Up @@ -186,17 +186,21 @@ int bmi_start_mgr(bmi_port_mgr_t* port_mgr) {
}

int bmi_port_create_mgr(bmi_port_mgr_t **port_mgr, int max_port_count) {
bmi_port_mgr_t *port_mgr_ = malloc(sizeof(bmi_port_mgr_t));
int exitCode;

if (!port_mgr) return -1;

bmi_port_mgr_t *port_mgr_ = malloc(sizeof(bmi_port_mgr_t));

memset(port_mgr_, 0, sizeof(bmi_port_mgr_t));

port_mgr_->max_port_count = max_port_count;
port_mgr_->ports = calloc(max_port_count, sizeof(*port_mgr_->ports));

if (socketpair(PF_LOCAL, SOCK_STREAM, 0, port_mgr_->socketpairfd)) {
perror("socketpair");
free(port_mgr_->ports);
free(port_mgr_);
return -1;
}

Expand Down

0 comments on commit 779a19b

Please sign in to comment.