For what i'm creating is not necessary checking if the image exists cause it always exists.
I would suggest you read more about pointers in C language because it does not seem you understand what you are doing.
A pointer is more or less the same as a memory address.
When you want to declare an object (here a "Bitmap" type object) in memory , you need to allocate it first.
This is what the "malloc" function does.
That function returns a memory address if it was able to allocate memory for that object and NULL if there wasn't enough memory left for it.
So yes, it's necessary to check the return value after calling malloc, it has nothing to do with "checking the image exists" (whatever that means) but is checking that memory was properly allocated for the Bitmap object before attempting to write to it.
Writing to an uninitialized pointer is like trying to write to address zero in memory, which generally causes a crash.
I give you another question: http://gbatemp.net/attachments/libjpeg_example-zip.14595/
The code i wrote is inspired from this sample.
Then why it works and mine not?
The sample code in that link (main.c) does not use a pointer to a "Bitmap" type object.
Your code wants to return a pointer to a "Bitmap" type object but never allocates memory for that object.
That's the difference and the reason it crashes, as explained already to you several times now.











