Module: kamailio
Branch: master
Commit: c4521d05cb90773e6a50747a4dc1f069617d7843
URL: 
https://github.com/kamailio/kamailio/commit/c4521d05cb90773e6a50747a4dc1f069617d7843

Author: Xenofon Karamanos <22965395+xkara...@users.noreply.github.com>
Committer: Henning Westerholt <h...@gilawa.com>
Date: 2025-06-06T15:43:16+02:00

file_out: Memory allocation and copy when used.

---

Modified: src/modules/file_out/file_out.c
Modified: src/modules/file_out/types.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/c4521d05cb90773e6a50747a4dc1f069617d7843.diff
Patch: 
https://github.com/kamailio/kamailio/commit/c4521d05cb90773e6a50747a4dc1f069617d7843.patch

---

diff --git a/src/modules/file_out/file_out.c b/src/modules/file_out/file_out.c
index 7a275d59022..ecd8298a874 100644
--- a/src/modules/file_out/file_out.c
+++ b/src/modules/file_out/file_out.c
@@ -589,9 +589,31 @@ static int fo_write_to_file(sip_msg_t *msg, char *index, 
char *log_message)
                fo_prefix_val.len = fo_prefix_str.len;
        }
 
+       /* Allocate memory */
+       logMessage.prefix = (str *)shm_malloc(sizeof(str));
+       if(logMessage.prefix == NULL) {
+               SHM_MEM_ERROR;
+               return -1;
+       }
+
+       logMessage.message = (str *)shm_malloc(sizeof(str));
+       if(logMessage.message == NULL) {
+               SHM_MEM_ERROR;
+               return -1;
+       }
+
+       /* Copy the value */
+       if(shm_str_dup(logMessage.prefix, &fo_prefix_val) < 0) {
+               LM_ERR("Failed to copy prefix\n");
+               return -1;
+       }
+
+       if(shm_str_dup(logMessage.message, &value) < 0) {
+               LM_ERR("Failed to copy message\n");
+               return -1;
+       }
+
        /* Add the logging string to the global gueue */
-       logMessage.prefix = &fo_prefix_val;
-       logMessage.message = &value;
        logMessage.dest_file = file_index;
        fo_enqueue(fo_queue, logMessage);
 
diff --git a/src/modules/file_out/types.c b/src/modules/file_out/types.c
index 0ae9bc7b063..5b9a62112f4 100644
--- a/src/modules/file_out/types.c
+++ b/src/modules/file_out/types.c
@@ -37,36 +37,6 @@ static fo_node_t *fo_new_node(fo_log_message_t data)
 
 int fo_enqueue(fo_queue_t *q, fo_log_message_t data)
 {
-       /*
-       Copy the contents of data.message
-    */
-       str *message_copy = 0;
-       str *prefix_copy = 0;
-       /*
-        * Allocate memory for the message and prefix
-        */
-       message_copy = (str *)shm_malloc(sizeof(str));
-       if(message_copy == 0) {
-               SHM_MEM_ERROR;
-               return -1;
-       }
-       if(shm_str_dup(message_copy, data.message) < 0) {
-               LM_ERR("Failed to duplicate message\n");
-               return -1;
-       }
-       data.message = message_copy;
-
-       prefix_copy = (str *)shm_malloc(sizeof(str));
-       if(prefix_copy == 0) {
-               SHM_MEM_ERROR;
-               return -1;
-       }
-       if(shm_str_dup(prefix_copy, data.prefix) < 0) {
-               LM_ERR("Failed to duplicate prefix\n");
-               return -1;
-       }
-       data.prefix = prefix_copy;
-
        fo_node_t *temp = fo_new_node(data);
 
        lock_get(&(q->lock));

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to