News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

HeapAlloc

Started by Darrel, July 21, 2006, 02:47:44 AM

Previous topic - Next topic

Darrel

I am having problems with the following:

INVOKE HeapAlloc,hHeap,HEAP_ZERO_MEMORY,32776 ;kernel32.dll


Whenever I try to save a certain bitmap as a gif with transparency and interlaced this function causes my program to terminate. I don't seem to have a clue why this is so. The function is located in the compression procedure and works fine if I save with only transparency or only interlacing or neither.

Puzzled,

Darrel

zooba

Probably some of the surrounding code is the problem then.

How do you set the value of hHeap? Does it change anywhere? Do you check for a null-pointer afterwards? If you run this part through a debugger, do you get messages telling you about heap corruption? Do you get a dialog box informing you of the error or does the program just close? Is the compression procedure your own or is it part of a library? Was the heap created with HEAP_GENERATE_EXCEPTIONS? There's a lot of helpful information you can give us. :wink

Cheers,

Zooba :U

Darrel

Quote from: zooba on July 21, 2006, 03:03:23 AM
How do you set the value of hHeap?

   INVOKE   GetProcessHeap                           ;kernel32.dll

   mov   hHeap,eax

Quote from: zooba on July 21, 2006, 03:03:23 AM
Does it change anywhere?

No.

Quote from: zooba on July 21, 2006, 03:03:23 AM
Do you check for a null-pointer afterwards?

No.

Quote from: zooba on July 21, 2006, 03:03:23 AM
If you run this part through a debugger, do you get messages telling you about heap corruption?

I do all debugging myself by inserting a procedure to write down register values at different places and displaying MessagBoxes to find where the problem occurs

Quote from: zooba on July 21, 2006, 03:03:23 AM
Do you get a dialog box informing you of the error or does the program just close?

It just closes. I display a MessageBox just before this function and just after, only the first MessageBox is displayed.

Quote from: zooba on July 21, 2006, 03:03:23 AM
Is the compression procedure your own or is it part of a library?

My own.

Quote from: zooba on July 21, 2006, 03:03:23 AM
Was the heap created with HEAP_GENERATE_EXCEPTIONS?

No.

It works fine on a different bitmap.

Regards,

Darrel




zooba

The most telling answer is that it just disappears. Possibly you have an infinite recursive loop in there which is eating up all the stack space. When a process runs out of stack space it simply disappears, rather than displaying an error message.

Posting some of the surrounding code would be very helpful.

Cheers,

Zooba :U

Darrel

INVOKE MessageBox,NULL,ADDR AppName,ADDR AppName,MB_OK

INVOKE HeapAlloc,hHeap,HEAP_ZERO_MEMORY or HEAP_GENERATE_EXCEPTIONS,32776 ;kernel32.dll

mov lpLZWTable,eax
mov edi,eax

INVOKE MessageBox,NULL,ADDR AppName,ADDR AppName,MB_OK


There is no loop. The first MessageBox is displayed, then after I click OK the program goes away

I just tried moving it out of the compression procedure to the save as gif procedure and making lpLZWTable a Global variable and it worked, however I had to make another HeapAlloc for the animated gif procedure and I placed MessageBoxes around it and only one of them was displayed then after I clicked OK my program vanished again.

Regards,

Darrel

Darrel

Here is the program with the MessageBoxes surrounding the HeapAlloc API. Also 2 pictures. The larger one causes the problem when saving as interlaced transparent gif. The smaller one no problem. Also, if you save the larger one only interlaced or only transparent or neither it works fine.

Regards,

Darrel

[attachment deleted by admin]

KSS

1. You see this in your Windows?
2. What OS you use?

[attachment deleted by admin]

Darrel


zooba

Source would be easier and quicker, especially if it's only of the particular section, but I'm in the mood for debugging, so you're lucky :wink

The following came out of my testing:

Quote from: OllyDbgDebug string: HEAP[ABitmapEditor.exe]:
Debug string: Heap block at 001CA940 modified at 001D2A6C past requested size of 8124
INT3 command at ntdll.DbgBreakPoint

Debug string: HEAP[ABitmapEditor.exe]:
Debug string: Invalid Address specified to RtlFreeHeap( 00140000, 001CA948 )
INT3 command at ntdll.DbgBreakPoint

Access violation when reading [010100F9]
Access violation when reading [010100F9]
Access violation when reading [010100F9]
Exception C0000017 (NO MEMORY)
Exception C0000017 (NO MEMORY)

So you do in fact have some heap corruption going on here, as well as passing an invalid address to HeapFree. This is followed by some access violations (possibly not yours) and a NO_MEMORY exception. I expect that you're allocating too big a chunk for the process heap. You should probably use HeapCreate to create your heap instead. This will let you set a larger minimum size and no maximum, so the heap will grow as required.

Cheers,

Zooba :U

KSS

Darrel,
Try to use VirtualAlloc() function.

Darrel

HeapCreate seems to have solved the problem.

What debugger do you use?

Thanks for your time and consideration,

Darrel

zooba

VirtualAlloc may be a better solution for this application, since you are dealing with images which could conceivably become quite large.

I use OllyDdb. The latest version is 1.10 and works very well in almost everything I've needed it for (trips up on SSE registers, but that's it)

Cheers,

Zooba :U

Darrel

Try setting one of the pixels (black) on the top row of the large bitmap and you can save the image as an interlaced and transparent gif.  :8)

Still puzzled by this anomaly,

Darrel