This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/16463] New: [3.4 Regression] Memory leak with simple code (code generation bug?)


This small program shows a memory leak with GCC 3.4.1 but not with mainline:

-----------------------------------------------------------
#include <memory>
#include <new>
#include <string>
#include <stdio.h>

typedef std::pair<unsigned, std::string> uint_str_t;
std::pair<unsigned, std::string>  g_key_id_name_pairs[] = {
    uint_str_t(64, "@"),
    uint_str_t(65, "A"),
    uint_str_t(66, "B")
};

static size_t alloc_cnt;

void* operator new(size_t size) throw(std::bad_alloc)
{
    printf("operator new is called \n");
    void* p = malloc(size);
    if (p == NULL)
        throw std::bad_alloc();
    alloc_cnt++;
    return p;
}

void operator delete(void* p) throw()
{
    printf("operator delete is called \n");
    if (p == NULL)
        return;
    alloc_cnt--;
    if (alloc_cnt == 0)
        printf("All memory released \n");
    else
        printf("%u allocations to be released \n", alloc_cnt);
}

int main()
{
}
-----------------------------------------------------------

The problem *seems* to be the compiler, so I file it against G++. We need a 
minimization to confirm exactly this bug.

This was reported by Wu Yong Wei on the v3 list:
(http://gcc.gnu.org/ml/libstdc++/2004-07/msg00038.html)

-- 
           Summary: [3.4 Regression] Memory leak with simple code (code
                    generation bug?)
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: giovannibajo at libero dot it
                CC: adah at netstd dot com,gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16463


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]