Skip to content

Commit

Permalink
[mms-lib] Improving error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Mar 4, 2014
1 parent bb20c1f commit 969fda8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mms-lib/src/mms_attachment.c
Expand Up @@ -51,7 +51,7 @@ mms_attachment_finalize(
{
MMSAttachment* at = MMS_ATTACHMENT(object);
MMS_VERBOSE_("%p", at);
g_mapped_file_unref(at->map);
if (at->map) g_mapped_file_unref(at->map);
if (!at->config->keep_temp_files &&
!(at->flags & MMS_ATTACHMENT_KEEP_FILES)) {
char* dir = g_path_get_dirname(at->original_file);
Expand Down
8 changes: 6 additions & 2 deletions mms-lib/src/mms_attachment_image.c
Expand Up @@ -249,7 +249,12 @@ mms_attachment_image_resize(
MMSAttachment* at)
{
MMSAttachmentImage* image = MMS_ATTACHMENT_IMAGE(at);
gboolean ok = mms_attachment_image_resize_type_specific(image);
gboolean ok;
if (at->map && image->resized) {
g_mapped_file_unref(at->map);
at->map = NULL;
}
ok = mms_attachment_image_resize_type_specific(image);
#ifdef HAVE_IMAGEMAGICK
if (!ok) ok = mms_attachment_image_resize_imagemagick(image);
#endif /* HAVE_IMAGEMAGICK */
Expand All @@ -258,7 +263,6 @@ mms_attachment_image_resize(
GMappedFile* map = g_mapped_file_new(image->resized, FALSE, &error);
if (map) {
at->file_name = image->resized;
if (at->map) g_mapped_file_unref(at->map);
at->map = map;
} else {
MMS_ERR("%s", MMS_ERRMSG(error));
Expand Down
4 changes: 2 additions & 2 deletions mms-lib/src/mms_attachment_jpeg.c
Expand Up @@ -225,8 +225,8 @@ mms_attachment_jpeg_resize_free(
MMSAttachmentJpegResize* jpeg = mms_attachment_jpeg_resize_cast(resize);
jpeg_destroy_compress(&jpeg->comp);
jpeg_destroy_decompress(&jpeg->decomp);
fclose(jpeg->in);
fclose(jpeg->out);
if (jpeg->in) fclose(jpeg->in);
if (jpeg->out) fclose(jpeg->out);
g_free(jpeg);
}

Expand Down
12 changes: 8 additions & 4 deletions mms-lib/test/resize/test_resize.c
Expand Up @@ -82,8 +82,12 @@ test_png_size(
static const TestImageType test_jpeg =
{ "image/jpeg", test_jpeg_size };

static const TestImageType test_auto =
#ifdef HAVE_MAGIC
static const TestImageType test_auto_jpeg =
{ NULL, test_jpeg_size };
#else
# define test_auto_jpeg test_jpeg
#endif

static const TestImageType test_png =
{ "image/png", test_png_size };
Expand Down Expand Up @@ -113,20 +117,20 @@ static const TestDesc resize_tests[] = {
},{
"Jpeg_Landscape1",
"data/0002.jpg",
&test_auto,
&test_auto_jpeg,
1,
1000000,
{1088, 613}
},{
"Jpeg_Landscape2",
"data/0002.jpg",
&test_auto, 2,
&test_auto_jpeg, 2,
2000000,
{1088, 613}
},{
"Jpeg_Landscape3",
"data/0002.jpg",
&test_auto,
&test_auto_jpeg,
3,
3000000,
{816, 460}
Expand Down

0 comments on commit 969fda8

Please sign in to comment.