From e4bbe15fc4c692d13b7ebe92ebfffa3eff3f0356 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sat, 2 Jan 2010 16:50:37 +0100 Subject: [PATCH] Infobar: Fix memleak in infobar_draw_statustext by replacing pointer to array --- src/infobar.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/infobar.c b/src/infobar.c index 8217f02..87cdc0d 100644 --- a/src/infobar.c +++ b/src/infobar.c @@ -171,8 +171,8 @@ infobar_draw_taglist(int sc) void infobar_draw_statustext(int sc, char *str) { - char *buf = NULL; - char *strwc = NULL; + char buf[512] = { 0 }; + char strwc[512] = { 0 }; char col[8] = { 0 }; int i, j, c, k = 0; char *lastst; @@ -187,10 +187,12 @@ infobar_draw_statustext(int sc, char *str) lastst = infobar[sc].statustext; infobar[sc].statustext = _strdup(str); - strwc = _strdup(str); + strcpy(strwc, &str[sizeof(strwc)]); /* Count how many color block there is and make a string without color block (\#....\)*/ - for(i = j = c = 0; i < strlen(str); ++i, ++j) + for(i = j = c = 0; + i < ((strlen(str) > sizeof(strwc)) ? sizeof(strwc) : strlen(str)); + ++i, ++j) { if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\') { @@ -211,14 +213,14 @@ infobar_draw_statustext(int sc, char *str) /* Draw text with its color */ if(c) { - buf = _strdup(strwc); + strcpy(buf, strwc); for(i = k; i < strlen(str); ++i, ++k) if(str[i] == '\\' && str[i + 1] == '#' && str[i + 8] == '\\') { /* Store current color in col[] */ for(j = 0, ++i; str[i] != '\\'; col[j++] = str[i++]); - buf += k; + strcpy(buf, &buf[k]); /* Draw a rectangle with the bar color to draw the text properly */ draw_rectangle(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(buf), @@ -229,17 +231,14 @@ infobar_draw_statustext(int sc, char *str) draw_text(infobar[sc].bar->dr, (sgeo[sc].width - SHADH) - textw(buf), FHINFOBAR, col, 0, buf); - buf = _strdup(strwc); + strcpy(buf, strwc); ++i; } - - free(buf); } barwin_refresh(infobar[sc].bar); free(lastst); - free(strwc); return; }