Skip to content

Commit 4dd3c79

Browse files
committed
Fix double free
1 parent be4f1bd commit 4dd3c79

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/draw.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ void gradient_pattern(struct gradient *grad)
115115
}
116116
}
117117

118+
struct gradient *gradient_copy(const struct gradient *grad)
119+
{
120+
if (grad == NULL)
121+
return NULL;
122+
123+
struct gradient *copy = gradient_alloc(grad->length);
124+
memcpy(copy->colors, grad->colors, grad->length * sizeof(struct color));
125+
gradient_pattern(copy);
126+
return copy;
127+
}
128+
118129
char *gradient_to_string(const struct gradient *grad)
119130
{
120131
if (!GRADIENT_VALID(grad)) return NULL;

src/draw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void gradient_free(struct gradient *grad);
6767

6868
void gradient_pattern(struct gradient *grad);
6969

70+
struct gradient *gradient_copy(const struct gradient *grad);
71+
7072
char *gradient_to_string(const struct gradient *grad);
7173

7274

src/notification.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ void notification_init(struct notification *n)
513513
if (!COLOR_VALID(n->colors.bg)) n->colors.bg = defcolors.bg;
514514
if (!COLOR_VALID(n->colors.frame)) n->colors.frame = defcolors.frame;
515515

516-
if (!GRADIENT_VALID(n->colors.highlight)) n->colors.highlight = defcolors.highlight;
516+
if (!GRADIENT_VALID(n->colors.highlight)) n->colors.highlight = gradient_copy(defcolors.highlight);
517517

518518
/* Sanitize misc hints */
519519
if (n->progress < 0)

0 commit comments

Comments
 (0)