aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-10-10 14:21:18 +0200
committerGravatar Christian Hesse <mail@eworm.de>2016-10-10 14:31:25 +0200
commit5972c031ba01cce93b33860643d9594ef8a0d7a5 (patch)
tree3a3d30c5877d7080e76a405ab47256c986e3f0de
parentc5cb165178d4d3dd5e59d43bb903e2cc48a55ca6 (diff)
downloadmpd-notification-5972c031ba01cce93b33860643d9594ef8a0d7a5.tar.gz
mpd-notification-5972c031ba01cce93b33860643d9594ef8a0d7a5.tar.zst
add more error handling
Signed-off-by: Christian Hesse <mail@eworm.de>
-rw-r--r--mpd-notification.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/mpd-notification.c b/mpd-notification.c
index b35396a..cdd28df 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -79,7 +79,11 @@ GdkPixbuf * retrieve_artwork(const char * music_dir, const char * uri) {
GdkPixbufLoader * loader;
/* try album artwork first */
- uri_path = malloc(strlen(music_dir) + strlen(uri) + 2);
+ if ((uri_path = malloc(strlen(music_dir) + strlen(uri) + 2)) == NULL) {
+ fprintf(stderr, "%s: malloc() failed.\n", program);
+ goto fail;
+ }
+
sprintf(uri_path, "%s/%s", music_dir, uri);
if ((magic_mime = magic_file(magic, uri_path)) == NULL) {
@@ -93,7 +97,10 @@ GdkPixbuf * retrieve_artwork(const char * music_dir, const char * uri) {
if (strcmp(magic_mime, "audio/mpeg") != 0)
goto image;
- pFormatCtx = avformat_alloc_context();
+ if ((pFormatCtx = avformat_alloc_context()) == NULL) {
+ fprintf(stderr, "%s: avformat_alloc_context() failed.\n", program);
+ goto image;
+ }
if (avformat_open_input(&pFormatCtx, uri_path, NULL, NULL) != 0) {
fprintf(stderr, "%s: avformat_open_input() failed", program);
@@ -116,8 +123,15 @@ GdkPixbuf * retrieve_artwork(const char * music_dir, const char * uri) {
pkt = pFormatCtx->streams[i]->attached_pic;
loader = gdk_pixbuf_loader_new();
- gdk_pixbuf_loader_write(loader, pkt.data, pkt.size, NULL);
- pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+ if (gdk_pixbuf_loader_write(loader, pkt.data, pkt.size, NULL) == FALSE) {
+ fprintf(stderr, "%s: gdk_pixbuf_loader_write() failed parsing file.\n", program);
+ goto image;
+ }
+
+ if ((pixbuf = gdk_pixbuf_loader_get_pixbuf(loader)) == NULL) {
+ fprintf(stderr, "%s: gdk_pixbuf_loader_get_pixbuf() failed creating pixbuf.\n", program);
+ goto image;
+ }
gdk_pixbuf_loader_close(loader, NULL);
goto done;
@@ -148,9 +162,19 @@ image:
if (verbose > 0)
printf("%s: Found image file: %s\n", program, entry->d_name);
- imagefile = malloc(strlen(uri_path) + strlen(entry->d_name) + 2);
+ if ((imagefile = malloc(strlen(uri_path) + strlen(entry->d_name) + 2)) == NULL) {
+ fprintf(stderr, "%s: malloc() failed.\n", program);
+ goto fail;
+ }
+
sprintf(imagefile, "%s/%s", uri_path, entry->d_name);
- pixbuf = gdk_pixbuf_new_from_file(imagefile, NULL);
+
+ if ((pixbuf = gdk_pixbuf_new_from_file(imagefile, NULL)) == NULL) {
+ fprintf(stderr, "%s: gdk_pixbuf_new_from_file() failed loading file: %s\n",
+ program, imagefile);
+ goto fail;
+ }
+
free(imagefile);
break;
}