Skip to content

Commit

Permalink
clients/upsmon.c: parse_status(): fix releasing of ups->status_tokens [
Browse files Browse the repository at this point in the history
…#415, #2709]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Dec 5, 2024
1 parent c9dac61 commit 9af439d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,13 @@ static void parse_status(utype_t *ups, char *status)
if (node->left) {
node->left->right = node->right; /* May be NULL*/
}
/* forget the neighbors before dropping the "tree" */

if (node == ups->status_tokens) {
ups->status_tokens = node->left ? node->left : node->right;
}

/* forget the neighbors before dropping the remaining
* "tree" of one node */
node->right = NULL;
node->left = NULL;

Expand All @@ -2696,8 +2702,12 @@ static void parse_status(utype_t *ups, char *status)
do_notify(ups, NOTIFY_OTHER, other_stat_words);
} else {
do_notify(ups, NOTIFY_NOTOTHER, NULL);
state_infofree(ups->status_tokens);
ups->status_tokens = NULL;

/* No words remain, drop the tree if still there */
if (ups->status_tokens) {
state_infofree(ups->status_tokens);
ups->status_tokens = NULL;
}
}
}

Expand Down

0 comments on commit 9af439d

Please sign in to comment.