log: set empty string to not set log_fields

not all functions in glib returns a value for the used log fields
in this case a 'g_return_val_if_fail(..) will only set 4 fields an
set the other field to NULL which leads to a segfault

Jul 22 13:41:37 Cynap-Pro-01121508 systemd-coredump[7247]: Process 496 (wireplumber) of user 4242 dumped core.

                                                           Stack trace of thread 496:
                                                           #0  0x00007f6b2ce58e99 __strlen_avx2 (libc.so.6 + 0x150e99)
                                                           #1  0x00007f6b2cf3ebe5 g_log_writer_journald (libglib-2.0.so.0 + 0x5fbe5)
                                                           #2  0x00007f6b2d0a9316 wp_log_fields_write_to_journal (libwireplumber-0.5.so.0 + 0x2b316)
                                                           #3  0x00007f6b2d0a96f5 wp_log_writer_default (libwireplumber-0.5.so.0 + 0x2b6f5)
                                                           #4  0x00007f6b2cf3cf3e g_log_structured_array (libglib-2.0.so.0 + 0x5df3e)
                                                           #5  0x00007f6b2cf3d0ae g_log_structured_array (libglib-2.0.so.0 + 0x5e0ae)
                                                           #6  0x00007f6b2cf3d4b7 g_logv (libglib-2.0.so.0 + 0x5e4b7)
                                                           #7  0x00007f6b2cf3d7ef g_log (libglib-2.0.so.0 + 0x5e7ef)
                                                           #8  0x00007f6b29efafef get_node_by_id (libwireplumber-module-cb-ipc.so + 0x24fef)
                                                           #9  0x00007f6b29efb032 wp_cb_ipc_get_app_properties (libwireplumber-module-cb-ipc.so + 0x25032)
This commit is contained in:
Stefan Ursella 2023-07-22 16:04:42 +02:00 committed by George Kiagiadakis
parent 72edbb1ba4
commit 7ee69a9a47

View file

@ -576,11 +576,11 @@ wp_log_fields_write_to_journal (WpLogFields *lf)
gsize n_fields = 6;
GLogField fields[6] = {
{ "PRIORITY", log_level_info[lf->log_level].priority, -1 },
{ "CODE_FILE", lf->file, -1 },
{ "CODE_LINE", lf->line, -1 },
{ "CODE_FUNC", lf->func, -1 },
{ "TOPIC", lf->log_topic, -1 },
{ "MESSAGE", lf->message, -1 },
{ "CODE_FILE", lf->file ? lf->file : "", -1 },
{ "CODE_LINE", lf->line ? lf->line : "", -1 },
{ "CODE_FUNC", lf->func ? lf->func : "", -1 },
{ "TOPIC", lf->log_topic ? lf->log_topic : "", -1 },
{ "MESSAGE", lf->message ? lf->message : "", -1 },
};
/* the log level flags are not used in this function, so we can pass 0 */