Bug Summary

File:.build-ci/../plugins/micron/micron-utils.c
Warning:line 60, column 9
Potential leak of memory pointed to by 'ctrl_name'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name micron-utils.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -fcoverage-compilation-dir=/__w/nvme-cli/nvme-cli/.build-ci -resource-dir /usr/lib/llvm-19/lib/clang/19 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I nvme.p -I . -I .. -I ccan -I ../ccan -I libnvme/src -I ../libnvme/src -I /usr/include/json-c -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -std=gnu99 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-opt-analyze-headers -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-06-24-175442-590-1 -x c ../plugins/micron/micron-utils.c
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (c) 2025 Micron Technology, Inc.
4 *
5 * Authors: Broc Going <bgoing@micron.com>
6 */
7
8#include <string.h>
9
10#include <libnvme.h>
11
12#include "micron-utils.h"
13#include "util/cleanup.h"
14
15char *micron_get_ctrl_name(struct libnvme_transport_handle *hdl)
16{
17 const char *name = libnvme_transport_handle_get_name(hdl);
18 char *ctrl_name = NULL((void*)0);
19
20 if (libnvme_transport_handle_is_ctrl(hdl)) {
2
Assuming the condition is true
3
Taking true branch
21 ctrl_name = strdup(name);
4
Memory is allocated
22 } else {
23 const char *p = strlen(name) > 4 ? strchr(name + 4, 'n') : NULL((void*)0);
24
25 ctrl_name = p ? strndup(name, p - name) : strdup(name);
26 }
27
28 return ctrl_name;
29}
30
31char *micron_get_ns_name(struct libnvme_transport_handle *hdl)
32{
33 const char *name = libnvme_transport_handle_get_name(hdl);
34 char *ns_name = NULL((void*)0);
35
36 if (libnvme_transport_handle_is_ns(hdl)) {
37 ns_name = strdup(name);
38 } else {
39 if (asprintf(&ns_name, "%sn1", name) < 0)
40 return NULL((void*)0);
41 }
42
43 return ns_name;
44}
45
46char *micron_get_ctrl_sysfs_dir(
47 struct libnvme_global_ctx *ctx,
48 struct libnvme_transport_handle *hdl)
49{
50 libnvme_ctrl_t c = NULL((void*)0);
51 __cleanup_free__attribute__((cleanup(freep))) char *ctrl_name = NULL((void*)0);
52 char *sysfs_dir = NULL((void*)0);
53
54 ctrl_name = micron_get_ctrl_name(hdl);
1
Calling 'micron_get_ctrl_name'
5
Returned allocated memory
55 if (ctrl_name && libnvme_scan_ctrl(ctx, ctrl_name, &c) == 0) {
6
Assuming 'ctrl_name' is non-null
7
Assuming the condition is false
8
Taking false branch
56 sysfs_dir = strdup(libnvme_ctrl_get_sysfs_dir(c));
57 libnvme_free_ctrl(c);
58 }
59
60 return sysfs_dir;
9
Potential leak of memory pointed to by 'ctrl_name'
61}