Dear All,

How to clean up memory leak in unmanage code?

I have unmanage code as below:

Code:
 //API declaration's
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "lstrcpyA")]
private static extern int StringCchCopy(int lpstring1, int lpstring2);
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "lstrcpyA")]
private static extern int StringCchCopy(byte[] lpstring1, int lpstring2);
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "lstrcpyA")]
private static extern int StringCchCopy(string lpstring1, string lpstring2);
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "lstrlenA")]
private static extern int lstrlen(int lpString);


public string getStrFromPtr(int StrPointer)
{
   string EndBuffer = "";
   byte[] StrBuffer;
   try
    {
	int strLen;
	strLen = lstrlen(StrPointer);
	StrBuffer = new byte[strLen + 1];
	if (strLen > 0)
	{
		StringCchCopy(StrBuffer, StrPointer);
	}
	for (int i = 0; i < strLen; i++)
	{
		EndBuffer += System.Convert.ToChar(StrBuffer[i]);
	}
     }
	catch (Exception ex) { SaveErrorLog("ClsMain.getStrFromPtr: " + ex.ToString()); }
	finally { StrBuffer = null; }
	return EndBuffer;
}