Can someone tell me why this code segfaults? I've read the man pages for both malloc and free and everything seems in order. Furthermore, most issues seem to come from assigning strings to memory allocated by malloc, but that is clearly not the issue here.
FILE *inFile = fopen(inptr, "r");
if(inFile == NULL){
fprintf(stderr, "Couldn't open input file\n");
return 2;
}
FILE *outFile = fopen(outptr, "w");
if(outFile == NULL){
fprintf(stderr, "Couldn't create output file\n");
return 2;
}
char *temp = malloc((fileLength + 1)* sizeof(char));
fread(&temp, fileLength, 1, inFile);
fwrite(&temp, sizeof(temp), 1, outFile);
fclose(inFile);
fclose(outFile);
free(temp);
free(temp);
which cause the segfault.