pointer confusion :(

Discussion in 'C++' started by mandatory, Feb 6, 2005.

  1. mandatory

    mandatory Guest

    hi,

    im getting confused.

    I have a memory leak in a routine and found that problem.

    I have a routine:

    void* PopQueue ()
    {
    void *item;

    //...pop the item

    return item;
    }

    The item was created with HeapAlloc() in the Push() routine.

    In another segment of my program i have this:

    void thereisdata()
    {
    MyqueueStruct *myitem;
    myItem = (myitem *) PopQueue();
    // process the data inside (this is working fine)
    HeapFree (GetProcessHeap(),0, myItem); // ERRROR !
    }

    This raises an exception, and i can see that the memory isnt freed.

    What im wondering now is what im doing wrong ? cant i free a pointer that
    points to a memory location like the way i do it in PopQueue() ?

    Hope you can help me - its starting to annoy me.

    using WinXP.
     
    mandatory, Feb 6, 2005
    #1
    1. Advertising

  2. "mandatory" <> wrote...
    > [..]
    > I have a memory leak in a routine and found that problem.
    >
    > The item was created with HeapAlloc() in the Push() routine.
    >
    > In another segment of my program i have this:
    >
    > HeapFree (GetProcessHeap(),0, myItem); // ERRROR !
    >
    > This raises an exception, and i can see that the memory isnt freed.
    >
    > What im wondering now is what im doing wrong ? cant i free a pointer that
    > points to a memory location like the way i do it in PopQueue() ?
    >
    > Hope you can help me - its starting to annoy me.


    No, we can't. With the little code you provided it's only clear that
    you're using some non-standard functions to allocate and free your
    memory. You need to post your question where these functions are on
    topic. I recommend comp.os.ms-windows.programmer.win32.
     
    Victor Bazarov, Feb 6, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    717
    Chris Torek
    Feb 4, 2005
  2. jimjim
    Replies:
    16
    Views:
    852
    Jordan Abel
    Mar 28, 2006
  3. Kavya
    Replies:
    2
    Views:
    387
  4. Replies:
    4
    Views:
    1,286
    Fred Zwarts
    Jul 2, 2009
  5. A
    Replies:
    7
    Views:
    644
Loading...

Share This Page