66 * UltraGrid modules.
77 */
88/*
9- * Copyright (c) 2013-2025 CESNET
9+ * Copyright (c) 2013-2026 CESNET, zájmové sdružení právnických osob
1010 * All rights reserved.
1111 *
1212 * Redistribution and use in source and binary forms, with or without
5555#include " module.h"
5656#include " utils/list.h"
5757#include " utils/lock_guard.h"
58- #include " utils/macros.h" // for snprintf_ch
58+ #include " utils/macros.h" // for snprintf_ch, to_fourcc
5959
6060#define MAX_MESSAGES 100
6161#define MAX_MESSAGES_FOR_NOT_EXISTING_RECV 10
6262#define MOD_NAME " [messaging] "
63+ #define MSG_MAGIC to_fourcc (' m' , ' e' , ' s' , ' g' )
64+ #define RESP_MAGIC to_fourcc (' r' , ' e' , ' s' , ' p' )
6365
6466using namespace std;
6567using namespace ultragrid ;
6668
6769struct response {
70+ uint32_t magic;
6871 int status;
6972 char text[];
7073};
@@ -323,6 +326,7 @@ struct message *new_message(size_t len)
323326
324327 struct message *ret = (struct message *)
325328 calloc (1 , len);
329+ ret->magic = MSG_MAGIC ;
326330
327331 return ret;
328332}
@@ -338,6 +342,8 @@ void free_message(struct message *msg, struct response *r)
338342 return ;
339343 }
340344
345+ assert (msg->magic == MSG_MAGIC );
346+
341347 if (r) {
342348 if (msg->send_response ) {
343349 msg->send_response (msg->priv_data , r);
@@ -354,6 +360,7 @@ void free_message(struct message *msg, struct response *r)
354360 delete (shared_ptr<struct responder > *) msg->priv_data ;
355361 }
356362
363+ msg->magic = 0 ;
357364 free (msg);
358365}
359366
@@ -366,6 +373,7 @@ void free_message(struct message *msg, struct response *r)
366373struct response *new_response (int status, const char *text)
367374{
368375 struct response *resp = (struct response *) malloc (sizeof (struct response ) + (text ? strlen (text) : 0 ) + 1 );
376+ resp->magic = RESP_MAGIC ;
369377 resp->status = status;
370378 if (text) {
371379 strcpy (resp->text , text);
@@ -376,6 +384,11 @@ struct response *new_response(int status, const char *text)
376384}
377385
378386void free_response (struct response *r) {
387+ if (r == nullptr ) {
388+ return ;
389+ }
390+ assert (r->magic == RESP_MAGIC );
391+ r->magic = 0 ;
379392 free (r);
380393}
381394
0 commit comments