valgrind:
***
==489682== HEAP SUMMARY:
==489682== in use at exit: 472 bytes in 1 blocks
==489682== total heap usage: 2 allocs, 1 frees, 4,568 bytes allocated
==489682==
==489682== 472 bytes in 1 blocks are still reachable in loss record 1 of 1
==489682== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==489682== by 0x48E8AAD: __fopen_internal (iofopen.c:65)
==489682== by 0x48E8AAD: fopen@@GLIBC_2.2.5 (iofopen.c:86)
==489682== by 0x109805: BMP_openfile (in /home/riz/Desktop/SPBU/4-task/bmp.o)
==489682== by 0x109A4C: main (in /home/riz/Desktop/SPBU/4-task/bmp.o)
==489682==
==489682== LEAK SUMMARY:
==489682== definitely lost: 0 bytes in 0 blocks
==489682== indirectly lost: 0 bytes in 0 blocks
==489682== possibly lost: 0 bytes in 0 blocks
==489682== still reachable: 472 bytes in 1 blocks
==489682== suppressed: 0 bytes in 0 blocks
==489682==
***
Segmentation fault (core dumped)
Код:
int BMP_openfile(){
struct BMP_HEADER *header;
struct BMP_INFO *info;
FILE *fp = fopen("sample_24.bmp","rb");
if(fp == NULL){
fprintf(stdout, "Error open file.");
return EXIT_FAILURE;
}
fread(&header,sizeof(BITMAPFILEHEADER),1,fp);
fread(&info,sizeof(BITMAPINFOHEADER),1,fp);
if (header->file_type != 19778){
fprintf(stdout,"Error format. The converter only supports BMP format.");
fclose(fp);
return -1;
}
if (info->planes != 1){
fprintf(stdout, "Error planes. The number of planes must be 1.");
fclose(fp);
return -2;
}
if (info->bpp != 8 && info->bpp != 24){
fprintf(stdout,"Error bits per pixel error. The converter only supports 8 and 24 bits per pixel images.");
fclose(fp);
return -2;
}
if(info->compression != 0){
fprintf(stdout, "Error compression. Only uncompressed images are supported");
fclose(fp);
return -2;
}
//fseek(fp,header->pixel_data_offset,SEEK_SET);
struct Image *picture = BMP_readImage(info,fp,info->width,info->height);
if(!picture){
fclose(fp);
return -1;
}
free(fp);
fclose(fp);
create_BMP_Image(header,info,picture);
free_Image(picture);
return 0;
}
int main(){
BMP_openfile();
return 0;
}