I'd like to get your opinion on this. I'm writing a program. During some fixing up and testing, I realized I'm forgetting to free a piece of memory I'm using. So I did, but the problem is that it now throws a SEGFAULT (but it works fine w/o the free).
- allocating and assigning value
char* device = (char*) malloc(10 * sizeof(char));
if (device == NULL){
printf("[-] Bad pointer to devicePath. exiting..\n");
exit(EXIT_FAILURE);
}
device = "nvme";
- pass onto function (which forks and exec)
searchPathForDisk(device, devicePath);
- trying to set free
free(device); //causes SEG FAULT - why?
I thought it had something to do with the exec not finishing executing before I'm calling free, but that's not the case. Any ideas? Is it something related to exec?