log REFACTOR check return value
diff --git a/src/log.c b/src/log.c
index 90e66a0..f55880a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -182,13 +182,15 @@
 static struct ly_ctx_err_rec *
 ly_err_get_rec(const struct ly_ctx *ctx)
 {
-    struct ly_ctx_err_rec rec, *match = NULL;
+    struct ly_ctx_err_rec rec, *match;
 
     /* prepare record */
     rec.tid = pthread_self();
 
     /* get the pointer to the matching record */
-    lyht_find(ctx->err_ht, &rec, dict_hash((void *)&rec.tid, sizeof rec.tid), (void **)&match);
+    if (lyht_find(ctx->err_ht, &rec, dict_hash((void *)&rec.tid, sizeof rec.tid), (void **)&match)) {
+        return NULL;
+    }
 
     return match;
 }