In the following, I am trying to free and NULLify the char * after using memory allocated by malloc(). Please help me to identify the root cause.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
   char *str1="hello world";
   char *str2=malloc((strlen(str1)+1) * sizeof(char));
   str2=str1;
   printf("%s",str2);
   free(str2);
   str2=NULL;
}
--
Error is :
Segmentation fault (core dumped)
 
     
    