Bug Summary

File:.build-ci/../src/nvme-pci-ids.c
Warning:line 44, column 6
Potential leak of memory pointed to by 'ctrl_name'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name nvme-pci-ids.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 static -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/bin/../lib/clang/22 -include /__w/nvme-cli/nvme-cli/.build-ci/nvme-config.h -I nvme.p -I . -I .. -I src -I ../src -I ccan -I ../ccan -I libnvme/src -I ../libnvme/src -I shared -I ../shared -I /usr/include/json-c -D _FILE_OFFSET_BITS=64 -D _GNU_SOURCE -U NDEBUG -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -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 -fdwarf2-cfi-asm -o /__w/nvme-cli/nvme-cli/.build-ci/scan-results/2026-08-08-045408-589-1 -x c ../src/nvme-pci-ids.c
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2026 Micron Technology, Inc.
4 *
5 * Authors: Broc Going <bgoing@micron.com>
6 */
7
8#include <errno(*__errno_location ()).h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#include <libnvme.h>
14
15#include "nvme-pci-ids.h"
16#include "nvme-print.h"
17#include "cleanup.h"
18
19int nvme_get_pci_ids(struct libnvme_global_ctx *ctx,
20 struct libnvme_transport_handle *hdl,
21 __u32 *vid, __u32 *did,
22 __u32 *subsys_vid, __u32 *subsys_did,
23 __u32 *class_code)
24{
25 int ret;
26 const char *name;
27
28 __cleanup_free__attribute__((cleanup(shr_freep))) char *ctrl_name = NULL((void*)0);
29 __cleanup_free__attribute__((cleanup(shr_freep))) char *sysfs_dir = NULL((void*)0);
30
31 name = libnvme_transport_handle_get_name(hdl);
32 if (libnvme_transport_handle_is_ctrl(hdl)) {
1
Assuming the condition is false
33 ctrl_name = strdup(name);
34 } else {
35 /* Strip the 'nY' namespace suffix: "nvme0n1" -> "nvme0" */
36 const char *p = strlen(name) > 4 ? strchr(name + 4, 'n')_Generic (0 ? (name + 4) : (void *) 1, const void *: (const char
*) (strchr (name + 4, 'n')), default: strchr (name + 4, 'n')
)
: NULL((void*)0);
2
Taking false branch
3
Assuming the condition is false
4
'?' condition is false
37
38 ctrl_name = p
4.1
'p' is null
? strndup(name, p - name) : strdup(name);
5
'?' condition is false
6
Memory is allocated
39 }
40
41 if (!ctrl_name)
7
Assuming 'ctrl_name' is non-null
8
Taking false branch
42 return -ENOMEM12;
43
44 ret = __nvme_get_sysfs_dir(ctx, ctrl_name, &sysfs_dir);
9
Potential leak of memory pointed to by 'ctrl_name'
45 if (ret != 0)
46 return ret;
47
48 return __nvme_get_pci_ids(sysfs_dir, vid, did, subsys_vid, subsys_did,
49 class_code);
50}