3

I have enabled MALLOC_CHECK_ by setting it to 1 (tried with 2 and 3 as well) But I don't see it reporting any issues with the following c++ program:

  int n = atoi(argv[1]);
  std::cout<<"n = "<<n<<std::endl;
  char *buf = new char[n];

  for (int i = 0;i < n*n; i++)
  {
    buf++;
    *buf = 'x';
  }



std::cout<<"done"<<std::endl;

Am I missing something here ?

Techie
  • 44,706
  • 42
  • 157
  • 243
user947158
  • 73
  • 4
  • `char *buf = (char *)malloc(n);` – Maroun Nov 21 '12 at 17:18
  • 1
    operator new may invoke malloc. And in my environment (libstdc++) it is [link](http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/libsupc%2B%2B/new_op.cc?revision=193295&view=markup) – user947158 Nov 21 '12 at 17:49

1 Answers1

1

Try calling 'delete' in the end. For me gcc started flagging errors only when there was a call to 'free' in the end. Maybe an implementation detail.

mk_
  • 417
  • 1
  • 3
  • 13