473,327 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

IIS crash

1
Hi guys,

There is a C++ DLL that does image processing.
It allocates 30MB in runtime and when it returns from
an __stdcall it returns a 30-50K array of integers
as C# Int32. The allocation is done with CoTaskMemAlloc.
After compilation the DLL entry name is prefixed by _
and the number of bytes of the arguments is appended
after a @ sign e.g. int __stdcall my_function(int mf_input)
is exported as the entry _my_function@4.
The DLL was checked with Bounds Checker and was compiled
with MSVC 6 and then was compiled also with MSVC 8.
It was also tested with Memory Validator.
Heap bait test was also done. 10MB allocated with the new
opeartor in an exe prior to the DLL function call. All bytes were
intiated with numbers, then a call to the DLL function was
performed and then after the return the values of the bait array
were checked. The same was done with CoTaskMemAlloc.
No change was detected. Then a stack bait test was done very
similar to the previous bait test but this time the bait array was
defined on the stack. No problems were detected !!!
The DLL works fine with C++ compiled EXE but when called from a
Dot Net web service the IIS crashes after the return.

The C# programmer knows the length of the array which is returned
by CoTaskMemAlloc after the returned pointer is cast to an int **
pointer,

int *my_array;
int my_length;

// Here code intializes my_array with 'new' and also my_length.
// The first integer in my_array is a CRC number of the rest.
// ...

e.g.
extern "C" __declspec(dllexport)
int __stdcall my_function(int **mf_output_array)
{
if (NULL==mf_output_array) return MY_ARGS_ERROR;

*mf_output_array = (int *)CoTaskMemAlloc(my_length*sizeof(int));

if (!mf_output_array)
{
delete[] my_array;
my_array = NULL;
my_length = 0;
return MY_INSUFFICIENT_MEMORY_ERROR;
}

memcpy(*mf_output_array,mf_array,my_length*sizeof( int));
delete[] my_array;
my_array = NULL;
my_length = 0;

// The calling process is responsible of calling
// CoTaskMemFree(*mf_output_array).
}

Is it possible that CoTaskMemAlloc is not Int32 aligned ?
Other allocations are usually page aligned.
How does the marshaller know the length of the returned array ?
Jun 28 '07 #1
1 1449
weaknessforcats
9,208 Expert Mod 8TB
If the "bait array" is my_array and it is on the stack, then you can't delete it.

But this code doesn't look right:
if (!mf_output_array)
{
delete[] my_array;
my_array = NULL;
my_length = 0;
return MY_INSUFFICIENT_MEMORY_ERROR;
}
mf_output_array is the function argument. It is an int** and will always have a non-NULL address. I think you meant to check the return from CoTaskMemAlloc() so the code should be:

Expand|Select|Wrap|Line Numbers
  1. ]
  2. if (!(*mf_output_array))
  3. {
  4. delete[] my_array;
  5. my_array = NULL;
  6. my_length = 0;
  7. return MY_INSUFFICIENT_MEMORY_ERROR;
  8. }
  9.  
Jun 28 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
8
by: Eric Brunel | last post by:
Hi all, I was creating a Tkinter widget in the style of the reversed tabs below Excel worksheets and I stepped in a serious problem: the code I made makes python crash with a seg fault, bus...
0
by: roni | last post by:
hi. i have application written in vb.net + managed c++ dll that call also to unmanaged c++ function. the application crash. i open the dump file of the crash with WinDbg and that's is the...
10
by: xixi | last post by:
i have db2 udb v8.1 on windows 64 bit 2003 server, after db2 server start , i found this in the db2diag.log, is this error? 2004-05-05-15.28.30.780000 Instance:DB2 Node:000...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
14
by: JK Peck | last post by:
I have a fairly large Access application that ran correctly in Access 2000. After upgrading to Access 2003 (and recompiling and updating references), it reliably crashes at a certain point. If I...
34
by: NewToCPP | last post by:
Hi, Why does a C/C++ programs crash? When there is access to a null pointer or some thing like that programs crash, but why do they crash? Thanks.
12
by: benjamin.krulewitch | last post by:
I'm debugging an issue with a C program that causes the computer to crash, and I'm attempting to log information immediately before the crash occurs. I us my BKprintLog function (see below) to...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.