Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Analyzer: "Potential memory leak" warning from std::unique_ptr move-only assignment operator #31207

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR32234
Status NEW
Importance P enhancement
Reported by Kevin Marshall (marshallk@google.com)
Reported on 2017-03-10 14:38:21 -0800
Last modified on 2017-03-10 15:17:59 -0800
Version unspecified
Hardware PC Linux
CC ganna@apple.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
LLVM version: clang version 5.0.0 (trunk 296321)
Platform: Linux; target: Linux
Code:
https://cs.chromium.org/chromium/src/dbus/values_util.cc?rcl=094b5e38f83ceebb408911139f194dd3705e54be&l=199

[1375/20604] CXX obj/dbus/dbus/values_util.o
In file included from ../../dbus/values_util.cc:5:
In file included from ../../dbus/values_util.h:10:
In file included from ../../build/linux/debian_wheezy_amd64-
sysroot/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/memory:85:
../../build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-
gnu/4.6/../../../../include/c++/4.6/bits/unique_ptr.h:190:4: warning: Potential
memory leak
          return *this;
          ^
../../dbus/values_util.cc:94:3: note: Control jumps to 'case STRUCT:'  at line
197
  switch (reader->GetDataType()) {
  ^
../../dbus/values_util.cc:199:11: note: Assuming the condition is true
      if (reader->PopStruct(&sub_reader)) {
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../dbus/values_util.cc:199:7: note: Taking true branch
      if (reader->PopStruct(&sub_reader)) {
      ^
../../dbus/values_util.cc:200:53: note: Memory is allocated
        std::unique_ptr<base::ListValue> list_value(new base::ListValue);
                                                    ^~~~~~~~~~~~~~~~~~~
../../dbus/values_util.cc:201:9: note: Taking true branch
        if (PopListElements(&sub_reader, list_value.get()))
        ^
../../dbus/values_util.cc:202:11: note: Calling 'unique_ptr::operator='
          result = std::move(list_value);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-
gnu/4.6/../../../../include/c++/4.6/bits/unique_ptr.h:190:4: note: Potential
memory leak
          return *this;
          ^
1 warning generated.
Quuxplusone commented 7 years ago
Seeing a similar error for the array specialization of unique_ptr, too:

../../build/linux/debian_wheezy_amd64-sysroot/usr/lib/gcc/x86_64-linux-
gnu/4.6/../../../../include/c++/4.6/bits/unique_ptr.h:321:2: warning: Potential
memory leak
        return *this;
        ^
../../third_party/webrtc/modules/audio_coding/neteq/packet.cc:29:3: note:
Calling 'BufferT::SetData'
  clone.payload.SetData(payload.data(), payload.size());
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/webrtc/base/buffer.h:190:5: note: Calling
'BufferT::AppendData'
    AppendData(data, size);
    ^~~~~~~~~~~~~~~~~~~~~~
../../third_party/webrtc/base/buffer.h:233:5: note: Calling
'BufferT::EnsureCapacityWithHeadroom'
    EnsureCapacityWithHeadroom(new_size, true);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../third_party/webrtc/base/buffer.h:322:5: note: Taking false branch
    if (capacity <= capacity_)
    ^
../../third_party/webrtc/base/buffer.h:331:9: note: '?' condition is true
        extra_headroom ? std::max(capacity, capacity_ + capacity_ / 2)
        ^
../../third_party/webrtc/base/buffer.h:334:35: note: Memory is allocated
    std::unique_ptr<T[]> new_data(new T[new_capacity]);
                                  ^~~
../../third_party/webrtc/base/buffer.h:336:5: note: Calling move assignment
operator for 'unique_ptr'
    data_ = std::move(new_data);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Quuxplusone commented 7 years ago

Included this internally in rdar://problem/30958661 Re-enable reporting bugs that end in C++ stdlib