]> git.ipfire.org Git - thirdparty/iproute2.git/commit
lib/fs: fix memory leak in get_task_name()
authorAndrea Claudi <aclaudi@redhat.com>
Tue, 8 Mar 2022 17:04:56 +0000 (18:04 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Sat, 12 Mar 2022 03:10:48 +0000 (19:10 -0800)
commit1808f002dfdd33fc397151c30bcffcef25cb6ae9
tree38811581107ceb841db3cd671ca182f37c054e6b
parent62c0700c7b373ad71ef712e4c065610c80866440
lib/fs: fix memory leak in get_task_name()

asprintf() allocates memory which is not freed on the error path of
get_task_name(), thus potentially leading to memory leaks.
%m specifier on fscanf allocates memory, too, which needs to be freed by
the caller.

This reworks get_task_name() to avoid memory allocation.
- Pass a buffer and its length to the function, similarly to what
  get_command_name() does, thus avoiding to allocate memory for
  the string to be returned;
- Use snprintf() instead of asprintf();
- Use fgets() instead of fscanf() to limit string length.

Fixes: 81bfd01a4c9e ("lib: move get_task_name() from rdma")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
include/utils.h
ip/iptuntap.c
lib/fs.c
rdma/res-cmid.c
rdma/res-cq.c
rdma/res-ctx.c
rdma/res-mr.c
rdma/res-pd.c
rdma/res-qp.c
rdma/res-srq.c
rdma/stat.c