Skip to content

Commit 1d0f313

Browse files
committed
fixes #111: handle malloc failure in syslog
1 parent 69f09eb commit 1d0f313

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

syslog/syslog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ syslog_compose(uint8_t facility, uint8_t severity, const char *tag, const char *
380380
{
381381
DBG("[%dµs] %s id=%lu\n", WDEV_NOW(), __FUNCTION__, syslog_msgid);
382382
syslog_entry_t *se = os_zalloc(sizeof (syslog_entry_t) + 1024); // allow up to 1k datagram
383+
if (se == NULL) return NULL;
383384
char *p = se->datagram;
384385
se->tick = WDEV_NOW(); // 0 ... 4294.967295s
385386
se->msgid = syslog_msgid;
@@ -512,6 +513,7 @@ void ICACHE_FLASH_ATTR syslog(uint8_t facility, uint8_t severity, const char *ta
512513
// compose the syslog message
513514
void *arg = __builtin_apply_args();
514515
void *res = __builtin_apply((void*)syslog_compose, arg, 128);
516+
if (res == NULL) return; // compose failed, probably due to malloc failure
515517
syslog_entry_t *se = *(syslog_entry_t **)res;
516518

517519
// and append it to the message queue

0 commit comments

Comments
 (0)