This is what I get from valgrind:
==1654036== Thread 102:
==1654036== Invalid read of size 1
==1654036== at 0x491328C: _IO_file_fopen@@GLIBC_2.2.5 (fileops.c:225)
==1654036== by 0x4905B0D: __fopen_internal (iofopen.c:75)
==1654036== by 0x4905B0D: fopen@@GLIBC_2.2.5 (iofopen.c:86)
==1654036== by 0x10A9EC: readFromDisk (in /home/john/OS4061/p3/group/p3/web_server)
==1654036== by 0x10AC72: worker (in /home/john/OS4061/p3/group/p3/web_server)
==1654036== by 0x4866608: start_thread (pthread_create.c:477)
==1654036== by 0x49A2292: clone (clone.S:95)
==1654036== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==1654036==
==1654036==
==1654036== Process terminating with default action of signal 11 (SIGSEGV)
==1654036== Access not within mapped region at address 0x0
==1654036== at 0x491328C: _IO_file_fopen@@GLIBC_2.2.5 (fileops.c:225)
==1654036== by 0x4905B0D: __fopen_internal (iofopen.c:75)
==1654036== by 0x4905B0D: fopen@@GLIBC_2.2.5 (iofopen.c:86)
==1654036== by 0x10A9EC: readFromDisk (in /home/john/OS4061/p3/group/p3/web_server)
==1654036== by 0x10AC72: worker (in /home/john/OS4061/p3/group/p3/web_server)
==1654036== by 0x4866608: start_thread (pthread_create.c:477)
==1654036== by 0x49A2292: clone (clone.S:95)
And here is the function
int readFromDisk(char *mybuf, char *request) {
int num_bytes = 0;
FILE *file = fopen(request, O_RDONLY);
if(file == NULL){
return 0;
}
while(fread(mybuf,1, 1, file)!=EOF){
num_bytes++;
}
return num_bytes;
}
I have tried printing request and it is a valid file path.
Thank you in advance.