devlink: fix memory leak in cmd_dev_flash()
nlg_ntf is dinamically allocated in mnlg_socket_open(), and is freed on
the out: return path. However, some error paths do not free it,
resulting in memory leak.
This commit fix this using mnlg_socket_close(), and reporting the
correct error number when required.
Fixes: 9b13cddfe2 ("devlink: implement flash status monitoring")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
309e6027e5
commit
ec1346acbe
|
|
@ -3371,19 +3371,21 @@ static int cmd_dev_flash(struct dl *dl)
|
||||||
|
|
||||||
err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
|
err = _mnlg_socket_group_add(nlg_ntf, DEVLINK_GENL_MCGRP_CONFIG_NAME);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
goto err_socket;
|
||||||
|
|
||||||
err = pipe(pipe_fds);
|
err = pipe(pipe_fds);
|
||||||
if (err == -1)
|
if (err == -1) {
|
||||||
return -errno;
|
err = -errno;
|
||||||
|
goto err_socket;
|
||||||
|
}
|
||||||
pipe_r = pipe_fds[0];
|
pipe_r = pipe_fds[0];
|
||||||
pipe_w = pipe_fds[1];
|
pipe_w = pipe_fds[1];
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
close(pipe_r);
|
|
||||||
close(pipe_w);
|
close(pipe_w);
|
||||||
return -errno;
|
err = -errno;
|
||||||
|
goto out;
|
||||||
} else if (!pid) {
|
} else if (!pid) {
|
||||||
/* In child, just execute the flash and pass returned
|
/* In child, just execute the flash and pass returned
|
||||||
* value through pipe once it is done.
|
* value through pipe once it is done.
|
||||||
|
|
@ -3412,6 +3414,7 @@ static int cmd_dev_flash(struct dl *dl)
|
||||||
err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
|
err = _mnlg_socket_recv_run(dl->nlg, NULL, NULL);
|
||||||
out:
|
out:
|
||||||
close(pipe_r);
|
close(pipe_r);
|
||||||
|
err_socket:
|
||||||
mnlg_socket_close(nlg_ntf);
|
mnlg_socket_close(nlg_ntf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue