Valgrind Error: when used on exit: 72,704 bytes C ++ Initialization Strangeness list with char *

Question:

I have a strange problem that I did not expect. I have a class called "Answers" and inside the header this is:

class Answer { char* aText; bool b_correct; public: Answer():aText(0){;} //default constructor } 

The main (test) driver code is the following:

 int main(void) { static const unsigned int MAX_ANSWERS = 5; Answer answers[MAX_ANSWERS]; } 

The (unexpected) oddity I get is that the distribution is happening, and I haven't used it anywhere else in my code. I assume char * calls this on the initialization list.

I use valgrind to test my code, and I get 11 allocs and 10 frees. When I remove the initializer :aText(0) , the extra selection goes away.

I understand that this is poorly constructed code. I follow the course outline to learn how to write in C ++. Can someone help me understand how memory is allocated or what happens during an initialization list to trigger a call to a new one?

I know that the error comes from the code shown. I know that extra alloc is happening. When I compile and run only this code.

Valgrind Output:

 ==12598== Memcheck, a memory error detector ==12598== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==12598== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==12598== Command: ./Answers ==12598== ==12598== ==12598== HEAP SUMMARY: ==12598== in use at exit: 72,704 bytes in 1 blocks ==12598== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated ==12598== ==12598== LEAK SUMMARY: ==12598== definitely lost: 0 bytes in 0 blocks ==12598== indirectly lost: 0 bytes in 0 blocks ==12598== possibly lost: 0 bytes in 0 blocks ==12598== still reachable: 72,704 bytes in 1 blocks ==12598== suppressed: 0 bytes in 0 blocks ==12598== Rerun with --leak-check=full to see details of leaked memory ==12598== ==12598== For counts of detected and suppressed errors, rerun with: -v ==12598== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) 

Platform Information:

Fedora 22

gcc.x86_64 5.1.1-4.fc22

valgrind.x86_64 1: 3.10.1-13.fc22

codeblocks.x86_64 13.12-14.fc22

+4
source share
1 answer

This is a known GCC 5.1 error, not a valgrind error.

Details here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64535

Possible workarounds: Downgrade GCC to an earlier version or wait for Valgrind to update the fix for this error. Both solutions are developed by the respective communities.

+7
source

All Articles