[LLVMbugs] [Bug 13751] New: vector push_back strdup: Memory is never released

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Sep 1 10:47:52 PDT 2012


http://llvm.org/bugs/show_bug.cgi?id=13751

             Bug #: 13751
           Summary: vector push_back strdup: Memory is never released
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: roland at utk.edu
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 9143
  --> http://llvm.org/bugs/attachment.cgi?id=9143
Preprocessed file with stl from gcc 4.7

#include <vector>
#include <algorithm>
#include <string.h>

class a
{
public:
    ~a()
    {
        for (size_t i = 0; i < args_.size(); ++i)
        {
            std::free(args_[i]);
        }
    }
    void append(const char *arg)
    {
        char *newArg = strdup(arg);
        args_.push_back(newArg);
    }
private:
    std::vector<char *>     args_;
};

int main()
{
    a i;
    i.append("a");
}

gives 

test6.cc:28:5: warning: Memory is never released; potential leak of memory
pointed to by 'newArg'
    i.append("a");

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list