LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Strategy for debugging Memory (Heap) Errors

Hello,
I'm a student worker and got the order of extending a measurement server written by another student (it was his diploma).
It's a bit complicated, so i try to simplify.
The strukture of the hole server kann be broken in 5 chunks:
1. The client, sending commands to the server and receiving Values via TCP/IP (using Winsock)
2. the server, first creating a thread that handles all network communication (winsock).Also opening a pipe to communicate with
ExecuteMeasurment every time ExeMeas is started. Also starting the UCM-Server(5).
3. the ExecuteMeasurement Executable - when the client asks for a specific measurement, the server starts this executable
(to have a extra process) using the commandline to pass parameters. ExecMeas uses a seperate DLL(lib) for doing the actual
measurement (by using GetExternalModuleAddr). After measurement the results passend back from the lib, are send back
via a pipe to the Server.
4. the MeasurementDLL performs the actual measurement. To communicate with instruments (via GPIB) it uses a special
Driver called UCM (establishing a connection to the UCM-Server in the DLLs Loadcode).
5. The Universal Control Module is some kind of an additional abstraction Layer between measurement - software and the
instruments. It's purpose is to increase independence of the given hardware.Example: Instead of writing code like "perform
measurement OpticalPower  on a Optical Powermeter from Company X" you can write "perform measurement OpticalPower
on an Device of the class OpticalPowermeter". To use it, a standard instrument interface was created (fp,sub,obj..), but its a
bit more complicated - the UCM-Driver has a built in TCP/IP (using CVI functions)-Server and DDE Server. The UCM-Driver
was written by a extra senior programmer in another department of the company.
Now the Problem:
The student that orginally programmed the server had to add several instruments to the UCM-Driver (making a fork in the
UCM-Driver). All worked fine after the student left the company.Shortly after that the UCM-Driver was rewritten in most parts.
So my first task was to bring the two versions together again by adding the additional instruments that were needed by the
server to the new UCM-Version. And thats were the problems started. I was successfull except of one function. This
function is the only function that wants to return a string read from the GPIB Output of a Optical Spectrum Analyzer. No
other function (nor in the server, or other softwareproducts in the whole company) uses a char-array to return data
(self-evident the UCM-Driver supports returning char-arrays). Since then the ExecuteMeasurement executable randomly
crashes with an Exception (failed to write to Adress .....). I think it crashes when the programm tries to free memory, that
was prior (dynamically) allocated to house the results, that are returned from the MeasurementDLL, and after that written to
the pipe.
To find the error source i tried using the HeapValidate(GetProcessHeap() - function from windows. This detects a heap error
(randomly) just before entering the UCM-Driver-function via the MeasurementDLL (i placed the test function the code line
before the ucm-function call). I also got random heap-errors from inside the ucm-guts (a function thats frees memory is
testing the heap before freeing memory). Since i haven't developed the UCM-Driver, and its a very big beast, i can't
determine if there is an error in the UCM-Driver. I asked the UCM-Developer for help, and he checked the code of the
function that I've implented in it, and he says that they are OK, and that his UCM-Driver has no errors at all.
Does anyone has a suggestion how to track down the error ?? I'm desperate!!
Oh, I'm using CVI 5.5 on Win2K.
Thanks in advance
Andreas Longin
Siemens AG Bln
0 Kudos
Message 1 of 1
(3,124 Views)