Skip to content

Commit

Permalink
Fix double free
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed Aug 17, 2024
1 parent be4f1bd commit 4dd3c79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ void gradient_pattern(struct gradient *grad)
}
}

struct gradient *gradient_copy(const struct gradient *grad)
{
if (grad == NULL)
return NULL;

struct gradient *copy = gradient_alloc(grad->length);
memcpy(copy->colors, grad->colors, grad->length * sizeof(struct color));
gradient_pattern(copy);
return copy;
}

char *gradient_to_string(const struct gradient *grad)
{
if (!GRADIENT_VALID(grad)) return NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ void gradient_free(struct gradient *grad);

void gradient_pattern(struct gradient *grad);

struct gradient *gradient_copy(const struct gradient *grad);

char *gradient_to_string(const struct gradient *grad);


Expand Down
2 changes: 1 addition & 1 deletion src/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ void notification_init(struct notification *n)
if (!COLOR_VALID(n->colors.bg)) n->colors.bg = defcolors.bg;
if (!COLOR_VALID(n->colors.frame)) n->colors.frame = defcolors.frame;

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

/* Sanitize misc hints */
if (n->progress < 0)
Expand Down

0 comments on commit 4dd3c79

Please sign in to comment.