diff --git a/src/core.c b/src/core.c index 8751f219..e53b2723 100644 --- a/src/core.c +++ b/src/core.c @@ -1267,6 +1267,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(hddtemp, &update_hddtemp) if (arg) obj->data.s = strndup(arg, text_buffer_size); + obj->callbacks.free = &free_hddtemp; #endif /* HDDTEMP */ #ifdef TCP_PORT_MONITOR END OBJ_ARG(tcp_portmon, &tcp_portmon_update, "tcp_portmon: needs arguments") @@ -1748,15 +1749,6 @@ void free_text_objects(struct text_object *root, int internal) free_top(obj, internal); break; #endif /* __linux__ */ -#ifdef HDDTEMP - case OBJ_hddtemp: - if (data.s) { - free(data.s); - data.s = NULL; - } - free_hddtemp(); - break; -#endif /* HDDTEMP */ case OBJ_user_names: if (info.users.names) { free(info.users.names); diff --git a/src/hddtemp.c b/src/hddtemp.c index 315664ef..41781ce3 100644 --- a/src/hddtemp.c +++ b/src/hddtemp.c @@ -30,6 +30,7 @@ #include "conky.h" #include "logging.h" +#include "text_object.h" #include #include #include @@ -223,7 +224,7 @@ void update_hddtemp(void) { free(data); } -void free_hddtemp(void) +void free_hddtemp(struct text_object *obj) { free_hddtemp_info(); if (hddtemp_host) { @@ -234,6 +235,10 @@ void free_hddtemp(void) free(hddtemp_port); hddtemp_port = NULL; } + if (obj->data.s) { + free(obj->data.s); + obj->data.s = NULL; + } } int get_hddtemp_info(const char *dev, short *val, char *unit) diff --git a/src/hddtemp.h b/src/hddtemp.h index 1642e412..c6d982a1 100644 --- a/src/hddtemp.h +++ b/src/hddtemp.h @@ -6,7 +6,7 @@ void set_hddtemp_host(const char *); void set_hddtemp_port(const char *); void update_hddtemp(void); -void free_hddtemp(void); +void free_hddtemp(struct text_object *); int get_hddtemp_info(const char *, short *, char *); #endif /*HDDTEMP_H_*/