JPEG Encode memory leaks

When dealing with PR #915, I noticed some cases where malloc'd memory was not freed. 

@cgohlke Can you test this on Windows for me?