diff --git a/frontend/scanimage.c b/frontend/scanimage.c index ab46174c8..55f8aab59 100644 --- a/frontend/scanimage.c +++ b/frontend/scanimage.c @@ -40,15 +40,7 @@ #include #include #include - -#ifdef __FreeBSD__ -#include -#endif - -#if defined (__APPLE__) && defined (__MACH__) #include // for basename() -#endif - #include #include @@ -1261,7 +1253,21 @@ write_png_header (SANE_Frame format, int width, int height, int depth, int dpi, if ((is_gray_profile && color_type == PNG_COLOR_TYPE_GRAY) || (is_rgb_profile && color_type == PNG_COLOR_TYPE_RGB)) { - png_set_iCCP(*png_ptr, *info_ptr, basename(icc_profile), PNG_COMPRESSION_TYPE_BASE, icc_buffer, icc_size); + char *icc_profile_cp = strdup(icc_profile); + if (icc_profile_cp == NULL) + { + fprintf(stderr, "Memory allocation failure prevented the setting of PNG ICC profile.\n"); + } + else + { + png_set_iCCP (*png_ptr, + *info_ptr, + basename (icc_profile_cp), + PNG_COMPRESSION_TYPE_BASE, + icc_buffer, + icc_size); + free(icc_profile_cp); + } } else {