Thread: malloc then delete in C++

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    3,877

    malloc then delete in C++

    I am just learning how to use drmemory and am getting error below
    Code:
    INVALID HEAP ARGUMENT: allocated with malloc, freed with operator delete
    I am guessing that is undefined in C++ and can lead to run-time issues is this correct?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,165
    Yes, mix and match with malloc / new / new[] doesn't work.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    3,877
    Quote Originally Posted by Salem View Post
    Yes, mix and match with malloc / new / new[] doesn't work.
    Thank you.

    Looks like I need to see if the issue exists in wxWidgets git master (found the issue in wxWidgets 3.1.3)

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-07-2017, 01:10 PM
  2. New/delete vs malloc/free
    By KBriggs in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2009, 03:08 PM
  3. Replies: 17
    Last Post: 11-16-2006, 09:06 PM
  4. malloc & free in C vs. new & delete in C++
    By groberts1980 in forum C Programming
    Replies: 20
    Last Post: 10-17-2006, 10:00 PM
  5. Difference malloc and delete
    By Leite33 in forum C Programming
    Replies: 2
    Last Post: 10-09-2006, 03:37 PM

Tags for this Thread