#include #include #include char* StringAdd (char* x, char* y); void FreeMemory (void* z); #### #include "StringTest.h" char* StringAdd (char* x, char* y) { char* ReturnString; int Length = strlen(x) + strlen(y); ReturnString = (char*) malloc (Length*sizeof(char)); strcpy (ReturnString, x); strcat (ReturnString, y); return ReturnString; } void FreeMemory (void* z) { void* current = NULL; current = z; free (current); current = NULL; if (NULL == current ) { printf ("Memory deallocated\n"); } } #### #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #define XARG 123 #include "StringTest.h" MODULE = MyStringTest PACKAGE = MyStringTest char* TestStringAdd (a,b) char* a char* b CODE: char* c; char* d; int length; c = StringAdd(a, b); length = strlen(c); Newz (XARG, d, length, char*); strcpy (d, (const char*)c); // deallocate Memory FreeMemory (c); printf ("Name::%s\n", d); printf ("Length::%d\n", length); RETVAL = d; OUTPUT: RETVAL #### use Test; BEGIN { plan tests => 1 }; use MyStringTest; print MyStringTest::TestStringAdd(Pijush, Koley), "\n"; ok(1); # If we made it this far, we're ok.