MessageQueue: Fix destructor accessing Message properties after free

This was raised as a -Wmaybe-uninitialized warning by MinGW-GCC 15.2.1.
This commit is contained in:
Rémi Verschelde 2025-10-29 13:08:05 +01:00
parent 0687d5f29f
commit 318a9721b8
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 6 additions and 7 deletions

View file

@ -324,19 +324,18 @@ MessageQueue::~MessageQueue() {
while (read_pos < buffer_end) { while (read_pos < buffer_end) {
Message *message = (Message *)&buffer[read_pos]; Message *message = (Message *)&buffer[read_pos];
read_pos += sizeof(Message);
Variant *args = (Variant *)(message + 1); Variant *args = (Variant *)(message + 1);
int argc = message->args; int argc = message->args;
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
for (int i = 0; i < argc; i++) { for (int i = 0; i < argc; i++) {
args[i].~Variant(); args[i].~Variant();
} }
read_pos += sizeof(Variant) * argc;
} }
message->~Message();
read_pos += sizeof(Message); message->~Message();
if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) {
read_pos += sizeof(Variant) * message->args;
}
} }
singleton = nullptr; singleton = nullptr;

View file

@ -55,9 +55,9 @@ class MessageQueue {
struct Message { struct Message {
Callable callable; Callable callable;
int16_t type; int16_t type = 0;
union { union {
int16_t notification; int16_t notification = 0;
int16_t args; int16_t args;
}; };
}; };