Permalink
Browse files

Clean up a few valgrind errors, add realloc-failure handling for grap…

…hs. (#367)

I think this fixes #360
  • Loading branch information...
1 parent e84ca1f commit a58a6d4e081ca6ab241f20fcae80a6b6c31bf1c9 @dmcbride dmcbride committed with Feb 11, 2017
Showing with 10 additions and 5 deletions.
  1. +6 −2 src/specials.cc
  2. +2 −2 src/template.cc
  3. +2 −1 src/x11.cc
View
@@ -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;
}
View
@@ -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;
}
View
@@ -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]);

0 comments on commit a58a6d4

Please sign in to comment.