Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. caveats when using _malloc_dbg

caveats when using _malloc_dbg

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    are there any "known' caveats when using _malloc_dbg ? do I have to use the _free_dbg ? from the small tests I did, seems I can use _malloc_dbg and simply use free. Thanks. M.


    Maximilien Lincourt Your Head A Splode - Strong Bad

    B P 2 Replies Last reply
    0
    • M Maximilien

      are there any "known' caveats when using _malloc_dbg ? do I have to use the _free_dbg ? from the small tests I did, seems I can use _malloc_dbg and simply use free. Thanks. M.


      Maximilien Lincourt Your Head A Splode - Strong Bad

      B Offline
      B Offline
      Bo Hunter
      wrote on last edited by
      #2

      the docs on msdn say that you must use _free_dbg. Thank You Bo Hunter

      1 Reply Last reply
      0
      • M Maximilien

        are there any "known' caveats when using _malloc_dbg ? do I have to use the _free_dbg ? from the small tests I did, seems I can use _malloc_dbg and simply use free. Thanks. M.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        P Offline
        P Offline
        peterchen
        wrote on last edited by
        #3

        _malloc_dbg adds guard bytes, so free might leak (or tras hthe heap).


        we are here to help each other get through this thing, whatever it is Vonnegut jr.
        boost your code || Fold With Us! || sighist | doxygen

        T 1 Reply Last reply
        0
        • P peterchen

          _malloc_dbg adds guard bytes, so free might leak (or tras hthe heap).


          we are here to help each other get through this thing, whatever it is Vonnegut jr.
          boost your code || Fold With Us! || sighist | doxygen

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          peterchen wrote: guard bytes, Sir,If you don't Midn please tell me What is Guard bytes ----------------------------- "I Think this Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

          P 1 Reply Last reply
          0
          • T ThatsAlok

            peterchen wrote: guard bytes, Sir,If you don't Midn please tell me What is Guard bytes ----------------------------- "I Think this Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #5

            No need for the Sir, Sir :) malloc_dbg calls malloc, but requests a few more bytes. These bytes are filled with a predefined value. free_dbg then checks if these extra bytes still hold this value. If they did, you probably wrote beyond the allocated memory (The VC Runtime prints a diagnostic message to the debug output) Typical implementations add 4 bytes at the end. In this case, using free instead of _free_dbg is often not a problem, but depending on the implementation, it might leak the guard bytes. But if an implementation adds guard bytes *before* the memory provided to you (to detect underflows, which are less common), using free instead of -free_dbg is likely to corrupt the heap.


            we are here to help each other get through this thing, whatever it is Vonnegut jr.
            boost your code || Fold With Us! || sighist | doxygen

            T 1 Reply Last reply
            0
            • P peterchen

              No need for the Sir, Sir :) malloc_dbg calls malloc, but requests a few more bytes. These bytes are filled with a predefined value. free_dbg then checks if these extra bytes still hold this value. If they did, you probably wrote beyond the allocated memory (The VC Runtime prints a diagnostic message to the debug output) Typical implementations add 4 bytes at the end. In this case, using free instead of _free_dbg is often not a problem, but depending on the implementation, it might leak the guard bytes. But if an implementation adds guard bytes *before* the memory provided to you (to detect underflows, which are less common), using free instead of -free_dbg is likely to corrupt the heap.


              we are here to help each other get through this thing, whatever it is Vonnegut jr.
              boost your code || Fold With Us! || sighist | doxygen

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Yeah Right, I understand _malloc_dbg and _free_dbg thanks. About peterchen wrote: Sir That a way to Show Respect to Elder. Thanks Again Sir!!! ----------------------------- "I Think this Will Help" ----------------------------- Alok Gupta visit me at http://www.thisisalok.tk

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups