From: Jan Blunck Date: Mon, 1 Jun 2015 09:30:38 +0000 (+0200) Subject: log: fix crash after dump X-Git-Tag: spdx-start~9012 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=408a082c4a4ef4dd9a5b37e3217c0edb9b7f6b20;p=dpdk.git log: fix crash after dump In rte_log_dump_history() the log_history list is reinitialized without resetting the log_history_size. In the next call to rte_log_add_in_history() the log_history_size > RTE_LOG_HISTORY and the code unconditionally tries to remove the first entry: Program received signal SIGSEGV, Segmentation fault. rte_log_add_in_history ( buf=buf@entry=0x7f02035cd000 "[snip]\n", size=size@entry=86) at /usr/src/packages/BUILD/lib/librte_eal/common/eal_common_log.c:122 Signed-off-by: Jan Blunck Acked-by: Olivier Matz --- diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c index c903aa95d5..1ae8de7080 100644 --- a/lib/librte_eal/common/eal_common_log.c +++ b/lib/librte_eal/common/eal_common_log.c @@ -119,7 +119,10 @@ rte_log_add_in_history(const char *buf, size_t size) /* get a buffer for adding in history */ if (log_history_size > RTE_LOG_HISTORY) { hist_buf = STAILQ_FIRST(&log_history); - STAILQ_REMOVE_HEAD(&log_history, next); + if (hist_buf) { + STAILQ_REMOVE_HEAD(&log_history, next); + log_history_size--; + } } else { if (rte_mempool_mc_get(log_history_mp, &obj) < 0) @@ -234,6 +237,7 @@ rte_log_dump_history(FILE *out) rte_spinlock_lock(&log_list_lock); tmp_log_history = log_history; STAILQ_INIT(&log_history); + log_history_size = 0; rte_spinlock_unlock(&log_list_lock); for (i=0; i