As it is known copy-pasting code is bad practice, I did the same mistake.
I finally found the mistake and changed:
fwrite(&buffer, 1, block_size, card);
with:
fwrite(&buffer, 1, block_size, jpg);
and the empty file problem was resolved. It was a silly mistake.
Also looks like the missing block is not actually missing.
I have 50 complete JPGs and it passes check50
.