check return values of malloc and handle error.

added some missing includes, too.

closes #199.
This commit is contained in:
t5c 2014-11-04 15:14:22 +01:00
parent f3fcc109f4
commit eedd220e37
3 changed files with 16 additions and 0 deletions

10
dbus.c
View File

@ -1,10 +1,14 @@
/* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */ /* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */
#include <stdlib.h>
#include <stdio.h>
#include <glib.h> #include <glib.h>
#include <string.h>
#include <gio/gio.h> #include <gio/gio.h>
#include "dunst.h" #include "dunst.h"
#include "dbus.h" #include "dbus.h"
#include "notification.h" #include "notification.h"
#include "utils.h"
GDBusConnection *dbus_conn; GDBusConnection *dbus_conn;
@ -124,6 +128,9 @@ static void onNotify(GDBusConnection * connection,
gchar *summary = NULL; gchar *summary = NULL;
gchar *body = NULL; gchar *body = NULL;
Actions *actions = malloc(sizeof(Actions)); Actions *actions = malloc(sizeof(Actions));
if(actions == NULL) {
die("Unable to allocate memory", EXIT_FAILURE);
}
gint timeout = -1; gint timeout = -1;
/* hints */ /* hints */
@ -268,6 +275,9 @@ static void onNotify(GDBusConnection * connection,
} }
notification *n = malloc(sizeof(notification)); notification *n = malloc(sizeof(notification));
if(n == NULL) {
die("Unable to allocate memory", EXIT_FAILURE);
}
n->appname = appname; n->appname = appname;
n->summary = summary; n->summary = summary;
n->body = body; n->body = body;

View File

@ -319,6 +319,9 @@ int main(int argc, char *argv[])
if (settings.startup_notification) { if (settings.startup_notification) {
notification *n = malloc(sizeof(notification)); notification *n = malloc(sizeof(notification));
if(n == NULL) {
die("Unable to allocate memory", EXIT_FAILURE);
}
n->appname = strdup("dunst"); n->appname = strdup("dunst");
n->summary = strdup("startup"); n->summary = strdup("startup");
n->body = strdup("dunst is up and running"); n->body = strdup("dunst is up and running");

3
x.c
View File

@ -330,6 +330,9 @@ static cairo_surface_t *get_icon_surface(char *icon_path)
static colored_layout *r_init_shared(cairo_t *c, notification *n) static colored_layout *r_init_shared(cairo_t *c, notification *n)
{ {
colored_layout *cl = malloc(sizeof(colored_layout)); colored_layout *cl = malloc(sizeof(colored_layout));
if(cl = NULL) {
die("Unable to allocate memory", EXIT_FAILURE);
}
cl->l = pango_cairo_create_layout(c); cl->l = pango_cairo_create_layout(c);
if (!settings.word_wrap) { if (!settings.word_wrap) {