[LLVMbugs] [Bug 22954] New: false positive: Potential leak connected with memcpy

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Mar 19 02:56:19 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=22954

            Bug ID: 22954
           Summary: false positive: Potential leak connected with memcpy
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: krzysztof.golinski at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Hello,

$ cat a.c 
#include <string.h>
#include <stdlib.h>

struct aa {
    char *s;
    char data[123];
};

int main() {
    struct aa a = {0};
    a.s = strdup("hello");
    char input[] = {'a', 'b', 'c', 'd'};
    memcpy(a.data, input, 4);

    free(a.s);
    return 0;
}

This code snippet doesn't have memleak (tested with valgrind) but scan-build
complains about it. 
Tested with gcc and clang and on both the output is the same:
scan-build clang a.c
scan-build: Using '/home/dirdival/clang-3.6/bin/clang' for static analysis
a.c:15:5: warning: Potential leak of memory pointed to by 'a.s'
    free(a.s);
    ^~~~~~~~~

When I remove 2 lines everything works:
$ cat b.c
#include <string.h>
#include <stdlib.h>

struct aa {
    char *s;
    char data[123];
};

int main() {
    struct aa a = {0};
    a.s = strdup("hello");

    free(a.s);
    return 0;
}
$ scan-build clang b.c
scan-build: Using '/home/dirdival/clang-3.6/bin/clang' for static analysis
scan-build: Removing directory '/tmp/scan-build-2015-03-19-105501-3689-1'
because it contains no reports.
scan-build: No bugs found.

Additional information:
$ clang --version
clang version 3.6.0 (tags/RELEASE_360/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Regards,
Krzysztof

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150319/bda33998/attachment.html>


More information about the llvm-bugs mailing list