Module: kamailio
Branch: 5.8
Commit: 028ba8f9d6bc40dcd47e6a0e5b40e5b3e2ea7b17
URL:
https://github.com/kamailio/kamailio/commit/028ba8f9d6bc40dcd47e6a0e5b40e5b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Xenofon Karamanos <22965395+xkaraman(a)users.noreply.github.com>
Date: 2024-03-26T09:57:25Z
file_out: additional checks for silenting warnings
(cherry picked from commit 19894425684504e2a19622ae5a9cdfc565f16fd3)
---
Modified: src/modules/file_out/file_out.c
---
Diff:
https://github.com/kamailio/kamailio/commit/028ba8f9d6bc40dcd47e6a0e5b40e5b…
Patch:
https://github.com/kamailio/kamailio/commit/028ba8f9d6bc40dcd47e6a0e5b40e5b…
---
diff --git a/src/modules/file_out/file_out.c b/src/modules/file_out/file_out.c
index 549eaa6e48f..7e035f13359 100644
--- a/src/modules/file_out/file_out.c
+++ b/src/modules/file_out/file_out.c
@@ -226,28 +226,31 @@ static void fo_log_writer_process(int rank)
LM_ERR("deque error\n");
return;
}
- FILE *out = fo_get_file_handle(log_message.dest_file);
- if(out == NULL) {
- LM_ERR("file handle is NULL\n");
- return;
- }
+ if(log_message.message != NULL) {
+ FILE *out = fo_get_file_handle(log_message.dest_file);
+ if(out == NULL) {
+ LM_ERR("file handle is NULL\n");
+ return;
+ }
- /* Get prefix for the file */
- if(log_message.prefix != NULL && log_message.prefix->len > 0) {
- if(fprintf(out, "%.*s", log_message.prefix->len,
- log_message.prefix->s)
+ /* Get prefix for the file */
+ if(log_message.prefix != NULL && log_message.prefix->len > 0) {
+ if(fprintf(out, "%.*s", log_message.prefix->len,
+ log_message.prefix->s)
+ < 0) {
+ LM_ERR("Failed to write prefix to file with err {%s}\n",
+ strerror(errno));
+ }
+ }
+ if(fprintf(out, "%.*s\n", log_message.message->len,
+ log_message.message->s)
< 0) {
- LM_ERR("Failed to write prefix to file with err {%s}\n",
+ LM_ERR("Failed to write to file with err {%s}\n",
strerror(errno));
}
- }
- if(fprintf(out, "%.*s\n", log_message.message->len,
- log_message.message->s)
- < 0) {
- LM_ERR("Failed to write to file with err {%s}\n", strerror(errno));
- }
- if(fflush(out) < 0) {
- LM_ERR("Failed to flush file with err {%s}\n", strerror(errno));
+ if(fflush(out) < 0) {
+ LM_ERR("Failed to flush file with err {%s}\n", strerror(errno));
+ }
}
if(log_message.prefix != NULL) {
@@ -337,7 +340,11 @@ static int fo_fixup_free_int_pvar(void **param, int param_no)
static int fo_add_filename(modparam_t type, void *val)
{
- if(val != NULL && strlen((char *)val) == 0) {
+ if(val == NULL) {
+ LM_ERR("modparam value is null\n");
+ return -1;
+ }
+ if(strlen((char *)val) == 0) {
LM_ERR("modparam value is empty\n");
return -1;
}