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. free() fails in vc 6 debug mode

free() fails in vc 6 debug mode

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelpquestion
11 Posts 6 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.
  • L Offline
    L Offline
    leowwl
    wrote on last edited by
    #1

    while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

    D H H T J 5 Replies Last reply
    0
    • L leowwl

      while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      You would be well-served to narrow the code down to just the statements necessary required to produce the problem. As it stands, it could be one of the other allocations, or the code that is using list, slist, or nodes.

      leowwl wrote:

      list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int));

      What is list, slist, and e? Why are the return values from the two calls to calloc() not cast to an int*?


      "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

      "There is no death, only a change of worlds." - Native American Proverb

      H 1 Reply Last reply
      0
      • L leowwl

        while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

        H Offline
        H Offline
        hint_54
        wrote on last edited by
        #3

        Why don't you use new instead? (is it not c++?) regards hint_54

        1 Reply Last reply
        0
        • D David Crow

          You would be well-served to narrow the code down to just the statements necessary required to produce the problem. As it stands, it could be one of the other allocations, or the code that is using list, slist, or nodes.

          leowwl wrote:

          list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int));

          What is list, slist, and e? Why are the return values from the two calls to calloc() not cast to an int*?


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "There is no death, only a change of worlds." - Native American Proverb

          H Offline
          H Offline
          hint_54
          wrote on last edited by
          #4

          DavidCrow wrote:

          Why are the return values from the two calls to calloc() not cast to an int*?

          The calloc function returns a void* pointing to newly allocated data. It means that you only need to cast if the compiler complains. regards hint_54

          D 1 Reply Last reply
          0
          • H hint_54

            DavidCrow wrote:

            Why are the return values from the two calls to calloc() not cast to an int*?

            The calloc function returns a void* pointing to newly allocated data. It means that you only need to cast if the compiler complains. regards hint_54

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            hint_54 wrote:

            The calloc function returns a void* pointing to newly allocated data.

            I'm aware of what it does.

            hint_54 wrote:

            It means that you only need to cast if the compiler complains.

            I don't subscribe to that philosophy. As it stands, if list is an int*, a compiler error will result unless a cast is provided. I suspect that list is a void*.


            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

            "There is no death, only a change of worlds." - Native American Proverb

            H 1 Reply Last reply
            0
            • D David Crow

              hint_54 wrote:

              The calloc function returns a void* pointing to newly allocated data.

              I'm aware of what it does.

              hint_54 wrote:

              It means that you only need to cast if the compiler complains.

              I don't subscribe to that philosophy. As it stands, if list is an int*, a compiler error will result unless a cast is provided. I suspect that list is a void*.


              "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

              "There is no death, only a change of worlds." - Native American Proverb

              H Offline
              H Offline
              hint_54
              wrote on last edited by
              #6

              DavidCrow wrote:

              a compiler error will result unless a cast is provided

              Depends on the compiler you are using. Borland compilers (at least the older ones, don't know about the newest) would only issue a warning. You could simply ignore. I don't know wich compiler he is using, so I cant tell. regards hint_54 -- modified at 13:38 Thursday 6th April, 2006 Ups... I'm sorry, you are right. I didnt notice the title :-O regards

              D 1 Reply Last reply
              0
              • H hint_54

                DavidCrow wrote:

                a compiler error will result unless a cast is provided

                Depends on the compiler you are using. Borland compilers (at least the older ones, don't know about the newest) would only issue a warning. You could simply ignore. I don't know wich compiler he is using, so I cant tell. regards hint_54 -- modified at 13:38 Thursday 6th April, 2006 Ups... I'm sorry, you are right. I didnt notice the title :-O regards

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                This is a Microsoft VC++ forum and any answers given will/should reflect such.


                "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                "There is no death, only a change of worlds." - Native American Proverb

                H 1 Reply Last reply
                0
                • D David Crow

                  This is a Microsoft VC++ forum and any answers given will/should reflect such.


                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                  "There is no death, only a change of worlds." - Native American Proverb

                  H Offline
                  H Offline
                  hint_54
                  wrote on last edited by
                  #8

                  Yes, you are right. Please reread my previous post. regards hint_54

                  1 Reply Last reply
                  0
                  • L leowwl

                    while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

                    H Offline
                    H Offline
                    HvalaMne
                    wrote on last edited by
                    #9

                    It happens when you allocate too small heap to keep data. Code below causes such error:

                    char *buf = (char *)malloc(sizeof(char)); // just 1 byte allocated
                    strcpy(buf, "longlonglong string. You allocated only one byte, just one char, how you copy so many chars in place where room is only for one char?");
                    free(buf);

                    compiler just inform you that your data are not allocated right way and may be corrupted. -- modified at 18:37 Thursday 6th April, 2006

                    1 Reply Last reply
                    0
                    • L leowwl

                      while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #10

                      any reason why you don't use C++ memory management (new and delete) ??

                      1 Reply Last reply
                      0
                      • L leowwl

                        while using free() to free up calloc'ed arrays, I get the following error: ------------------------- Debug Assertion Failed! Program C:\...\sim.exe File: dbgheap.c Line:1017 Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts. (Press retry to debug this application) ------------ another error message i get ------ Program C:\...\sim.exe Debug Error! DAMAGE: after Normal block (#50) at 0x00440040 (Press retry to debug this application) ------------------------- the exact code used is: list=calloc(e,sizeof(int)); slist=calloc(e,sizeof(int)); nodes = (int *)malloc(nelems*sizeof(int)); . . . free((void *) list ); free((void *) slist); free(nodes); ---------------------- Does anyone know anything about this? Care to advise? Thanks in advance...

                        J Offline
                        J Offline
                        James R Twine
                        wrote on last edited by
                        #11

                        The first one means that the heap manager does not think that you are freeing a pointer to a valid block of memory.  The second usually means that you ran off the end of a block of allocated memory.    If the two errors happen on blocks of memory that were allocated back-to-back, I would think that you walked off the end of one block stepping on the next.    Check any code that copies data into the memory referenced by those pointers to make sure you are keeping the correct size constraints.    Peace! -=- James


                        If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                        DeleteFXPFiles & CheckFavorites (Please rate this post!)

                        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