From a58a6d4e081ca6ab241f20fcae80a6b6c31bf1c9 Mon Sep 17 00:00:00 2001 From: Darin McBride Date: Sat, 11 Feb 2017 14:39:18 -0700 Subject: [PATCH] Clean up a few valgrind errors, add realloc-failure handling for graphs. (#367) I think this fixes #360 --- src/specials.cc | 8 ++++++-- src/template.cc | 4 ++-- src/x11.cc | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/specials.cc b/src/specials.cc index 73bd2a22..d8ac8b0d 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -521,12 +521,16 @@ void new_graph(struct text_object *obj, char *buf, int buf_max_size, double val) /* initialize */ std::fill_n(graph, s->graph_width, 0.0); s->scale = 100; - } else { + } else if (graph) { if (s->graph_width > s->graph_allocated) { /* initialize the new region */ std::fill(graph + s->graph_allocated, graph + s->graph_width, 0.0); } - } + } else { + DBGP("reallocing FAILED"); + graph = s->graph; + s->graph_width = s->graph_allocated; + } s->graph = graph; s->graph_allocated = s->graph_width; } diff --git a/src/template.cc b/src/template.cc index 17d63b12..98b9f682 100644 --- a/src/template.cc +++ b/src/template.cc @@ -99,8 +99,8 @@ static char *backslash_escape(const char *src, char **templates, unsigned int te } p++; } - src_dup[dup_idx] = '\0'; - src_dup = (char*) realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char)); + src_dup[dup_idx++] = '\0'; + src_dup = (char*) realloc(src_dup, dup_idx * sizeof(char)); return src_dup; } diff --git a/src/x11.cc b/src/x11.cc index 682c8d72..216fe22e 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -491,7 +491,8 @@ static void update_workarea(void) workarea[0] = ps->x_org; workarea[1] = ps->y_org; workarea[2] = workarea[0] + ps->width; - workarea[3] = workarea[1] + ps->height; + workarea[3] = workarea[1] + ps->height; + XFree(si); DBGP("Fixed xinerama area to: %d %d %d %d", workarea[0], workarea[1], workarea[2], workarea[3]);