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. How to fix the invalide pointer problem

How to fix the invalide pointer problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++comperformancetutorial
4 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.
  • Y Offline
    Y Offline
    yu jian
    wrote on last edited by
    #1

    I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?

    L L S 3 Replies Last reply
    0
    • Y yu jian

      I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      Use the debugger .. you are a programmer!!!!!!! When it breaks it will give you the pointer that is involved ... now look at all code that uses the pointer. Also actually bother to look at any warning the compiler is spitting out. The other thing you can have done is forgot to initialize the pointer and you are assuming it is zero.

      pointer p; // not initialized
      pointer p = 0; // initialized

      This can give the weird behaviour that in debug mode the code will work but in release mode it will crash. The reason is in debug mode the compiled code takes the time to zero all variables for you and so both codes act the same, in release mode it will not zero variables and "p" will be initialized at some garbage value. You can generally pick this problem off by turning your warning level up to 4 on the compiler ... it will spit a warning ... "Possible use of uninitialized pointer"

      In vino veritas

      1 Reply Last reply
      0
      • Y yu jian

        I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Well, a memory leak is the opposite thing and happens when a pointer goes out of scope or is overwritten before the allocated memory was released. What you have is a faulty lifcycle management. You can't release an object and then try to use it again. Your program must make sure that pointers are initialized before being used and also that those pointers are not forgotten or overwritten. Begin with setting all pointers to NULL immediately after releasing the memory. This way you can at least check wether the pointer is NULL or contains a valid pointer before using it. To completely solve it, you should implement a better lifecycle management for your objects.

        The language is JavaScript. that of Mordor, which I will not utter here
        This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a fucking golf cart.
        "I don't know, extraterrestrial?" "You mean like from space?" "No, from Canada." If software development were a circus, we would all be the clowns.

        1 Reply Last reply
        0
        • Y yu jian

          I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER, I guess maybe the pointer is release, but then use this pointer. Is there anyway to check where the memory leak and where the pointer is released?

          S Offline
          S Offline
          Saravanan Sundaresan
          wrote on last edited by
          #4

          Running with a memory leak detector can help?

          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