Hello
I having some memory leaks working with structure pointer used by a DLL external function, that I call within a class used by a dataflex Web Server.
I make several tried and below is only one of the last, but the result is always the same.. All data are correctly read from the structure i using... and can be moved to dataflex string and last to a webform
but after that as soon I do NavigateForward or navigatebackward or repeating another call.. always I get an Access Violation popoup error.
below is a function that is used in this class
Code:
// this is the structure
Struct DMT_INFO_DER_BLOB //
Integer cbData
Address pbData
End_Struct
// this is the external function
External_Function dmtGetSignedInfoParam "dmtGetSignedInfoParam" DIMATECDLL ;
Integer TimestampParamType ;
Integer dwIndex;
Address pvData; // pointer to DMT_INFO_DER_BLOB
Address pcbData;
Returns Integer
// this function is within cObject base class "Class cDimatek is a cObject"
Function GetSingleCertValue Integer iparamtype Returns String
Integer dwParamLen i
Address pParam lpserialnumber
Integer VerifySignedFileResult iret
DMT_INFO_DER_BLOB pvdata
String SerialNumber
Move 0 to dwParamLen
// this call need to get the lenght alloc memory
Move (dmtGetSignedInfoParam(iparamtype, 0,0, (addressof( dwParamLen)))) to VerifySignedFileResult
If (VerifySignedFileResult = DMT_OK) Begin
Move (alloc (dwParamLen)) to pParam
Move (AddressOf(pvdata)) to pParam
Move 0 to SerialNumber
// this receive the pointer to the structure that contain the values in pParam
Move (dmtGetSignedInfoParam(iparamtype, 0, pParam, dwParamLen)) to VerifySignedFileResult
// fill the string that will receive the value
Move (Repeat(character(32), (pvdata.cbData))) to SerialNumber
If (VerifySignedFileResult = DMT_OK) Begin
Move (Alloc(pvdata.cbData)) to lpserialnumber
Move (addressof(SerialNumber)) to lpserialnumber
// this is how it work with c# to convert a pointer to structure
// DMT_INFO_DER_BLOB Param = (DMT_INFO_DER_BLOB)System.Runtime.InteropServices.Marshal.PtrToStructure(
// pParam, typeof(DMT_INFO_DER_BLOB));
// InforCertDialog.oSIG_SIG_SERIAL_NUMBER.Text = Param.pbData.ToString(); // new string(dimatekCertInfo.SerialNumber) ;
//
Move (MemCopy(lpserialnumber , pvdata.pbData, pvdata.cbData)) to iret
Move (Free (pParam)) to iret
Move (Free(lpserialnumber)) to iret
Move (Free( pvdata.pbData)) to iret
Function_Return SerialNumber // this is filled right and move back to webserveice
End
If (pParam>0) Move (Free (pParam)) to iret
If ( pvdata.pbData>0) Move (Free ( pvdata.pbData)) to iret
if ( lpserialnumber>0) Move (Free ( lpserialnumber)) to iret
End
Function_Return ""
End_Function
//**************
//this is the function within the webservice that call the function in the object class called owebdimatek
{ Published=True }
{ Description = "GetSingleCertValue"}
Function GetSingleCertificateValue Integer iparamtype Returns String
String svalue
Get GetSingleCertValue of owebdimatek iparamtype to svalue
Function_Return svalue
End_Function
//and this is the function that I call within the event onshow on the webview
Procedure OnShow
Forward Send OnShow
Integer iret isize i
String sfinalResult
Get GetSingleCertificateValue of oDimatecwebservice DMT_SIG_CER_SERIAL_NUMBER to sfinalResult
WebSet psValue of oWebFormsn to sfinalResult // this is ok the value is showed correctly
// but after that everything I will do like example a normal NavigateForward will get AccessViolation popup see below
End_Procedure
As soon I Try a Nabvigatebackward or Navigateforward from the view after the value is correctly showed i get AccessViolation Popoup and the debugger stop here within function CallAction :
Code:
{ Visibility=Private }
Function CallAction tWebRequest Request Returns tWebResponse
Handle hoTarget
Integer i icAction
Boolean bAllowAction bLoadWebApp
String sObjectName
tWebResponse Response
// Determine if this is the LoadWebApp call
If (SizeOfArray(Request.aActions) > 0) Begin
If (Request.aActions[0].sAction = "LoadWebApp") Begin
Move True to bLoadWebApp
End
End
// Process the Request Header....
Set pbSynchronizing to True
Get ProcessRequestHeader Request.Header bLoadWebApp to bAllowAction <<<<<<<<<
Set pbSynchronizing to False
I suppose that I missing something but I free the memory any time I used ALLOC I did a lot of try with string uChar and memcopy but the result is always the same I can read all values from the DLL structure POinter parameters but after that seem that the string memory have trouble... that I cannot solve... at this point
II sure that Dataaccess developers can have some suggestion that I missing..Anyway I suggest in the future to can have a Function like C# already have PtrToStructure that allow to get values from a pointer to a structure without take care about memory alloc and free
I don't know if this depend by the way I use to do this call
1.DLL with structures and external function->
2. DF Class cobject where are defined all functions that make direct calls to the dll->
3. webservice that call functions within the DF cobject class
4. webapp mobile view that call the webservice functions that call the class object functions that call the external DLL functions
regards
Franco Spinella