1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Fix 3 memleaks that happen when scroll receives wrong args

This commit is contained in:
Nikolas Garofil 2010-02-15 16:02:29 +01:00
parent 53af0f379f
commit a6debedc93
3 changed files with 11 additions and 5 deletions

View File

@ -136,7 +136,7 @@ static struct text_object *create_plain_text(const char *s)
}
/* construct_text_object() creates a new text_object */
struct text_object *construct_text_object(const char *s, const char *arg, long
struct text_object *construct_text_object(char *s, const char *arg, long
line, void **ifblock_opaque, void *free_at_crash)
{
// struct text_object *obj = new_text_object();
@ -1565,7 +1565,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
/* allocate a follower to reset any color changes */
obj->next = new_text_object_internal();
#endif /* BUILD_X11 */
parse_scroll_arg(obj, arg, free_at_crash);
parse_scroll_arg(obj, arg, free_at_crash, s);
obj->callbacks.print = &print_scroll;
obj->callbacks.free = &free_scroll;
END OBJ_ARG(combine, 0, "combine needs arguments: <text1> <text2>")

View File

@ -42,7 +42,7 @@ struct scroll_data {
long resetcolor;
};
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash)
void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash, char *free_at_crash2)
{
struct scroll_data *sd;
int n1 = 0, n2 = 0;
@ -52,8 +52,14 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr
sd->resetcolor = get_current_text_color();
sd->step = 1;
if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0)
if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0) {
free(sd);
#ifdef BUILD_X11
free(obj->next);
#endif
free(free_at_crash2);
CRIT_ERR(obj, free_at_crash, "scroll needs arguments: <length> [<step>] <text>");
}
sscanf(arg + n1, "%u %n", &sd->step, &n2);
if (*(arg + n1 + n2)) {

View File

@ -30,7 +30,7 @@
#ifndef _SCROLL_H
#define _SCROLL_H
void parse_scroll_arg(struct text_object *, const char *, void *);
void parse_scroll_arg(struct text_object *, const char *, void *, char *);
void print_scroll(struct text_object *, char *, int);
void free_scroll(struct text_object *);