From e6d9aa2b431a4914e1ae8e97b1718decc7eef7a1 Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Fri, 12 Jun 2015 10:25:09 -0700 Subject: [PATCH] mavlink fix for cause of intermittent crash If the posix target is run and the rootfs is not created, then there is an fopen in mavlink without a return value check and then a write to the fd. When this condition occurs it tries to write to NULL and will segfault. Signed-off-by: Mark Charlebois --- src/modules/mavlink/mavlink_messages.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 9d16363e66..f92876849c 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -409,9 +409,14 @@ protected: snprintf(log_file_path, sizeof(log_file_path), PX4_ROOTFSDIR"/fs/microsd/%s", log_file_name); fp = fopen(log_file_path, "ab"); - /* write first message */ - fputs(msg.text, fp); - fputs("\n", fp); + if (fp != NULL) { + /* write first message */ + fputs(msg.text, fp); + fputs("\n", fp); + } + else { + warn("Failed to open %s errno=%d", log_file_path, errno); + } } } }