Click here to Skip to main content
15,915,509 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dynamic lib code:
C
DYNAMICLIB_API int* aa1(void)
{
    int *a1;
    a1=(int*)malloc(sizeof(int));
    printf("Interger created\n");
    printf("bye");
    printf("good");
    printf("memory created");
     return a1;
}

my main function code:
C
int main(int argc, char* argv[])
{
    int *a1;
    a1=aa1();
    printf("Hello World!\n");
    free(a1);
    return 0;
}


that codeproducing run time error can you help me.
Posted
Updated 5-Jul-11 1:57am
v2

1 solution

You shouldn't allocate memory and release it in different modules, see "Allocating and freeing memory across module boundaries"[^].
The simpler solution is making your DLL exporting the 'release memory function'.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Jul-11 13:57pm    
Good advice, my 5. OP's questions are nearly spam; if you look at their history.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900