{"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
 "version": "2.1.0",
 "runs": [{"tool": {"driver": {"name": "GNU C23",
                               "fullName": "GNU C23 (GCC) version 16.1.1 20260703 (Red Hat 16.1.1-4) (x86_64-redhat-linux)",
                               "version": "16.1.1 20260703 (Red Hat 16.1.1-4)",
                               "informationUri": "https://gcc.gnu.org/gcc-16/",
                               "rules": [{"id": "-Wanalyzer-malloc-leak",
                                          "helpUri": "https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Static-Analyzer-Options.html#index-Wanalyzer-malloc-leak"}]}},
           "taxonomies": [{"name": "CWE",
                           "version": "4.7",
                           "organization": "MITRE",
                           "shortDescription": {"text": "The MITRE Common Weakness Enumeration"},
                           "taxa": [{"id": "401",
                                     "helpUri": "https://cwe.mitre.org/data/definitions/401.html"}]}],
           "invocations": [{"arguments": ["/usr/libexec/gcc/x86_64-redhat-linux/16/cc1",
                                          "-quiet",
                                          "-I",
                                          "../src/include/",
                                          "-D",
                                          "_GNU_SOURCE",
                                          "-D",
                                          "__SANE_USERSPACE_TYPES__",
                                          "-D",
                                          "_LARGEFILE_SOURCE",
                                          "-D",
                                          "_FILE_OFFSET_BITS=64",
                                          "-D",
                                          "LIBURING_BUILD_TEST",
                                          "-include",
                                          "../config-host.h",
                                          "fdinfo-sqpoll.c",
                                          "-quiet",
                                          "-dumpbase",
                                          "fdinfo-sqpoll.c",
                                          "-dumpbase-ext",
                                          ".c",
                                          "-m64",
                                          "-mtune=generic",
                                          "-march=x86-64",
                                          "-mtls-dialect=gnu2",
                                          "-O2",
                                          "-Wno-unused-parameter",
                                          "-Wno-sign-compare",
                                          "-Wno-unknown-pragmas",
                                          "-flto=auto",
                                          "-ffat-lto-objects",
                                          "-fexceptions",
                                          "-fstack-protector-strong",
                                          "-fasynchronous-unwind-tables",
                                          "-fstack-clash-protection",
                                          "-fcf-protection=full",
                                          "-fno-omit-frame-pointer",
                                          "-fanalyzer",
                                          "-fdiagnostics-path-format=separate-events",
                                          "-fno-diagnostics-show-caret",
                                          "-fno-lto",
                                          "-fanalyzer-assume-nothrow",
                                          "-fdiagnostics-text-art-charset=none",
                                          "-fdiagnostics-set-output=sarif:file=/builddir/gcc-results/2050-XnO3.sarif",
                                          "-o",
                                          "/tmp/cczdN6BC.s"],
                            "workingDirectory": {"uri": "/builddir/build/BUILD/liburing-2.13-build/liburing-2.13/test"},
                            "startTimeUtc": "2026-08-03T18:01:42Z",
                            "executionSuccessful": true,
                            "toolExecutionNotifications": [],
                            "endTimeUtc": "2026-08-03T18:01:42Z"}],
           "originalUriBaseIds": {"PWD": {"uri": "file:///builddir/build/BUILD/liburing-2.13-build/liburing-2.13/test/"}},
           "artifacts": [{"location": {"uri": "fdinfo-sqpoll.c",
                                       "uriBaseId": "PWD"},
                          "sourceLanguage": "c",
                          "contents": {"text": "/* SPDX-License-Identifier: MIT */\n/*\n * Description: Race fdinfo reading with SQPOLL thread exiting\n */\n#include <errno.h>\n#include <stdio.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <string.h>\n#include <fcntl.h>\n#include <sys/types.h>\n#include <pthread.h>\n\n#include \"helpers.h\"\n#include \"liburing.h\"\n\nstruct data {\n\tstruct io_uring ring;\n\tpthread_t thread;\n\tpthread_barrier_t barrier;\n\tvolatile int done;\n};\n\nstatic int rand_between(int a, int b)\n{\n\treturn a + rand() % (b - a + 1);\n}\n\nstatic void *fdinfo_read(void *__data)\n{\n\tstruct data *d = __data;\n\tchar fd_name[128];\n\tchar *buf;\n\tint fd;\n\n\tbuf = malloc(4096);\n\n\tsprintf(fd_name, \"/proc/self/fdinfo/%d\", d->ring.ring_fd);\n\tfd = open(fd_name, O_RDONLY);\n\tif (fd < 0) {\n\t\tperror(\"open\");\n\t\treturn NULL;\n\t}\n\n\tpthread_barrier_wait(&d->barrier);\n\n\tdo {\n\t\tint ret = read(fd, buf, 4096);\n\n\t\tif (ret < 0) {\n\t\t\tperror(\"fdinfo read\");\n\t\t\tbreak;\n\t\t}\n\t} while (!d->done);\n\n\tclose(fd);\n\tfree(buf);\n\treturn NULL;\n}\n\nstatic int __test(void)\n{\n\tstruct data d = { };\n\tvoid *tret;\n\tint ret;\n\n\tret = t_create_ring(8, &d.ring, IORING_SETUP_SQPOLL);\n\tif (ret == T_SETUP_SKIP)\n\t\texit(T_EXIT_SKIP);\n\telse if (ret < 0)\n\t\texit(T_EXIT_FAIL);\n\tpthread_barrier_init(&d.barrier, NULL, 2);\n\tpthread_create(&d.thread, NULL, fdinfo_read, &d);\n\tpthread_barrier_wait(&d.barrier);\n\tusleep(rand_between(1000, 100000));\n\td.done = 1;\n\tpthread_join(d.thread, &tret);\n\texit(T_EXIT_PASS);\n}\n\nstatic int test(void)\n{\n\tpid_t pid;\n\n\tpid = fork();\n\tif (pid) {\n\t\tint wstatus;\n\n\t\tusleep(rand_between(10, 2000));\n\t\tkill(pid, SIGINT);\n\t\twaitpid(pid, &wstatus, 0);\n\t} else {\n\t\treturn __test();\n\t}\n\n\treturn T_EXIT_PASS;\n}\n\nint main(int argc, char *argv[])\n{\n\tint i, ret;\n\n\tif (argc > 1)\n\t\treturn T_EXIT_SKIP;\n\n\tfor (i = 0; i < 1000; i++) {\n\t\tret = test();\n\t\tif (ret == T_EXIT_SKIP) {\n\t\t\treturn T_EXIT_SKIP;\n\t\t} else if (ret) {\n\t\t\tfprintf(stderr, \"test failed\\n\");\n\t\t\treturn T_EXIT_FAIL;\n\t\t}\n\t}\n\n\treturn T_EXIT_PASS;\n}\n"},
                          "roles": ["analysisTarget",
                                    "tracedFile"]}],
           "results": [{"ruleId": "-Wanalyzer-malloc-leak",
                        "taxa": [{"id": "401",
                                  "toolComponent": {"name": "cwe"}}],
                        "properties": {"gcc/analyzer/saved_diagnostic/sm": "malloc",
                                       "gcc/analyzer/saved_diagnostic/ploc": {"enode": 193},
                                       "gcc/analyzer/saved_diagnostic/var": "buf_10",
                                       "gcc/analyzer/saved_diagnostic/sval": "&HEAP_ALLOCATED_REGION(262)",
                                       "gcc/analyzer/saved_diagnostic/state": "unchecked ({free})",
                                       "gcc/analyzer/saved_diagnostic/idx": 0,
                                       "gcc/analyzer/saved_diagnostic/duplicates": [{"properties": {"gcc/analyzer/saved_diagnostic/sm": "malloc",
                                                                                                    "gcc/analyzer/saved_diagnostic/ploc": {"enode": 193},
                                                                                                    "gcc/analyzer/saved_diagnostic/var": "buf_10",
                                                                                                    "gcc/analyzer/saved_diagnostic/sval": "&HEAP_ALLOCATED_REGION(262)",
                                                                                                    "gcc/analyzer/saved_diagnostic/state": "unchecked ({free})",
                                                                                                    "gcc/analyzer/saved_diagnostic/idx": 1,
                                                                                                    "gcc/analyzer/pending_diagnostic/kind": "malloc_leak"}}],
                                       "gcc/analyzer/pending_diagnostic/kind": "malloc_leak"},
                        "level": "warning",
                        "message": {"text": "leak of ‘buf’"},
                        "locations": [{"physicalLocation": {"artifactLocation": {"uri": "fdinfo-sqpoll.c",
                                                                                 "uriBaseId": "PWD"},
                                                            "region": {"startLine": 59,
                                                                       "startColumn": 1,
                                                                       "endColumn": 2},
                                                            "contextRegion": {"startLine": 59,
                                                                              "snippet": {"text": "}\n"}}},
                                       "logicalLocations": [{"index": 0,
                                                             "fullyQualifiedName": "fdinfo_read"}]}],
                        "codeFlows": [{"threadFlows": [{"id": "main",
                                                        "locations": [{"properties": {"gcc/analyzer/checker_event/emission_id": "(1)",
                                                                                      "gcc/analyzer/checker_event/kind": "state_change"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "fdinfo-sqpoll.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 36,
                                                                                                                    "startColumn": 15,
                                                                                                                    "endColumn": 27},
                                                                                                         "contextRegion": {"startLine": 36,
                                                                                                                           "snippet": {"text": "\tbuf = malloc(4096);\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "fdinfo_read"}],
                                                                                    "message": {"text": "allocated here"}},
                                                                       "kinds": ["acquire",
                                                                                 "memory"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 1},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(2)",
                                                                                      "gcc/analyzer/checker_event/kind": "start_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 58,
                                                                                                                                 "dst_id": 59}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "fdinfo-sqpoll.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 40,
                                                                                                                    "startColumn": 12,
                                                                                                                    "endColumn": 13},
                                                                                                         "contextRegion": {"startLine": 40,
                                                                                                                           "snippet": {"text": "\tif (fd < 0) {\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "fdinfo_read"}],
                                                                                    "message": {"text": "following ‘true’ branch..."}},
                                                                       "kinds": ["branch",
                                                                                 "true"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 2},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(3)",
                                                                                      "gcc/analyzer/checker_event/kind": "end_cfg_edge",
                                                                                      "gcc/analyzer/superedge_event/superedge": {"src_id": 58,
                                                                                                                                 "dst_id": 59}},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "fdinfo-sqpoll.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 41,
                                                                                                                    "startColumn": 17,
                                                                                                                    "endColumn": 31},
                                                                                                         "contextRegion": {"startLine": 41,
                                                                                                                           "snippet": {"text": "\t\tperror(\"open\");\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "fdinfo_read"}],
                                                                                    "message": {"text": "...to here"}},
                                                                       "kinds": ["branch",
                                                                                 "true"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 3},
                                                                      {"properties": {"gcc/analyzer/checker_event/emission_id": "(4)",
                                                                                      "gcc/analyzer/checker_event/kind": "warning"},
                                                                       "location": {"physicalLocation": {"artifactLocation": {"uri": "fdinfo-sqpoll.c",
                                                                                                                              "uriBaseId": "PWD"},
                                                                                                         "region": {"startLine": 59,
                                                                                                                    "startColumn": 1,
                                                                                                                    "endColumn": 2},
                                                                                                         "contextRegion": {"startLine": 59,
                                                                                                                           "snippet": {"text": "}\n"}}},
                                                                                    "logicalLocations": [{"index": 0,
                                                                                                          "fullyQualifiedName": "fdinfo_read"}],
                                                                                    "message": {"text": "‘buf’ leaks here; was allocated at [(1)](sarif:/runs/0/results/0/codeFlows/0/threadFlows/0/locations/0)"}},
                                                                       "kinds": ["danger"],
                                                                       "nestingLevel": 1,
                                                                       "executionOrder": 4}]}]}]}],
           "logicalLocations": [{"name": "fdinfo_read",
                                 "fullyQualifiedName": "fdinfo_read",
                                 "decoratedName": "fdinfo_read",
                                 "kind": "function",
                                 "index": 0}]}]}
