Skip to content

[analyzer] Wrong warning location of memory leak #120586

Open
@mvpant

Description

@mvpant
// clang --analyze -Xanalyzer -analyzer-output=text

#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>

void leak(bool v1) {
  void* v3 = malloc(1);
  if (v3 != NULL) {
    int v5 = 0; // <--- warning: Potential leak of memory pointed to by 'v3' [unix.Malloc]
    if (v1) {
      return; // <--- Expected warning location
    }
  }
  return;
}

void leak2(bool v1) {
  void* v3 = malloc(1);
  if (v3 != NULL) {
    if (v1) { // <--- warning: Potential leak of memory pointed to by 'v3' [unix.Malloc]
      return; // <--- Expected warning location
    }
  }
  return;
}

void caller() {
  leak(1);
  leak2(1);
  return;
}

Godbolt example

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:static analyzerenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions