Hello, I am sending a task to the server, they write: "Memory leaks". For input: 3
#include <stdio.h> #include <stdlib.h> #include <string.h> char *fibstr(int n) { int i=0; char *s1; char *s2; int len1=1; int len2=1; int sum=0; char *s=(char*)calloc(2,sizeof(char)); char *s3; if(n==1) { strcpy(s,"a"); return s; } if(n==2) { strcpy(s,"b"); return s; } for(i=2; i<=n; i++) { sum=len1+len2; len1=len2; len2=sum; } s1 = (char*)calloc(sum,sizeof(char)); s2 = (char*)calloc(sum,sizeof(char)); s3 = (char*)calloc(sum,sizeof(char)); strcpy(s1,"a"); strcpy(s2,"b"); for(i=2; i<n; i++) { strcpy(s3,strcat(s1,s2)); strcpy(s1,s2); strcpy(s2,s3); } free(s1),free(s2); return s3; } int main() { int n=0; scanf("%d",&n); char *s=fibstr(n); printf("%s",s); free(s); return 0; } Help properly clean the memory.