1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-25 12:10:03 +00:00

ifblock: fix clash with specials when freeing objects

Murphy hit me again: in my naive attempt to fix the clash between
ifblocks and objects parsing text objects due to the double use of the
'sub' field, I overlooked this problem with reusing the 'special_data'
field. So here comes the real thing (TM), donating ifblocks their own
field for pointing to the jump target.
This commit is contained in:
Phil Sutter 2009-11-16 19:52:12 +01:00
parent 44f76f4876
commit 70e5afe5ac
4 changed files with 8 additions and 20 deletions

View File

@ -801,7 +801,8 @@ void generate_text_internal(char *p, int p_max_size,
*/
#define DO_JUMP { \
DBGP2("jumping"); \
obj = obj->special_data; \
if (obj->ifblock_next) \
obj = obj->ifblock_next; \
}
#define OBJ(a) break; case OBJ_##a:
@ -1167,7 +1168,7 @@ void generate_text_internal(char *p, int p_max_size,
* Do Ninja jump here: without leaving traces.
* This is to prevent us from stale jumped flags.
*/
obj = obj->special_data;
obj = obj->ifblock_next;
continue;
}
OBJ(endif) {

View File

@ -1336,7 +1336,6 @@ int extract_variable_text_internal(struct text_object *retval, const char *const
void free_text_objects(struct text_object *root, int internal)
{
struct text_object *obj;
char type_is_if;
if (!root->prev) {
return;
@ -1795,21 +1794,8 @@ void free_text_objects(struct text_object *root, int internal)
break;
#endif /* X11 */
}
type_is_if = 0;
if(obj->type == OBJ_if_gw || obj->type == OBJ_if_empty || obj->type == OBJ_if_match || obj->type == OBJ_if_existing || obj->type == OBJ_if_mounted || obj->type == OBJ_if_running || obj->type == OBJ_if_updatenr || obj->type == OBJ_if_mixer_mute) type_is_if = 1;
#if defined(IBM)
if(obj->type == OBJ_if_smapi_bat_installed) type_is_if = 1;
#endif
#if defined(__FreeBSD__) || defined(__linux__)
if(obj->type == OBJ_if_up) type_is_if = 1;
#endif
#ifdef MPD
if(obj->type == OBJ_if_mpd_playing) type_is_if = 1;
#endif
#ifdef XMMS2
if(obj->type == OBJ_if_xmms2_connected) type_is_if = 1;
#endif
if(obj->special_data && obj->type != OBJ_else && type_is_if == 0) free(obj->special_data);
if(obj->special_data)
free(obj->special_data);
free(obj);
}
#undef data

View File

@ -107,7 +107,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
case IFBLOCK_ENDIF:
if (!(*ifblock_stack_top))
CRIT_ERR(NULL, NULL, "got an endif without matching if");
(*ifblock_stack_top)->obj->special_data = obj;
(*ifblock_stack_top)->obj->ifblock_next = obj;
/* if there's some else in between, remove and free it */
if ((*ifblock_stack_top)->type == IFBLOCK_ELSE) {
stackobj = *ifblock_stack_top;
@ -122,7 +122,7 @@ static int push_ifblock(struct ifblock_stack_obj **ifblock_stack_top,
case IFBLOCK_ELSE:
if (!(*ifblock_stack_top))
CRIT_ERR(NULL, NULL, "got an else without matching if");
(*ifblock_stack_top)->obj->special_data = obj;
(*ifblock_stack_top)->obj->ifblock_next = obj;
/* fall through */
case IFBLOCK_IF:
stackobj = malloc(sizeof(struct ifblock_stack_obj));

View File

@ -472,6 +472,7 @@ enum text_object_type {
struct text_object {
struct text_object *next, *prev; /* doubly linked list of text objects */
struct text_object *sub; /* for objects parsing text into objects */
struct text_object *ifblock_next; /* jump target for ifblock objects */
union {
void *opaque; /* new style generic per object data */
char *s; /* some string */