<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - false positive: Potential leak connected with memcpy"
   href="https://llvm.org/bugs/show_bug.cgi?id=22954">22954</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>false positive: Potential leak connected with memcpy
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>krzysztof.golinski@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>