log UPDATE add ERRMEM check macros
diff --git a/src/io.c b/src/io.c
index 47894d4..d51278f 100644
--- a/src/io.c
+++ b/src/io.c
@@ -74,18 +74,12 @@
             /* add "; " */
             reason_size += 2;
             reasons = nc_realloc(reasons, reason_size);
-            if (!reasons) {
-                ERRMEM;
-                return NULL;
-            }
+            NC_CHECK_ERRMEM_RET(!reasons, NULL);
             reason_len += sprintf(reasons + reason_len, "; ");
         }
         reason_size += strlen(ERR_reason_error_string(e));
         reasons = nc_realloc(reasons, reason_size);
-        if (!reasons) {
-            ERRMEM;
-            return NULL;
-        }
+        NC_CHECK_ERRMEM_RET(!reasons, NULL);
         reason_len += sprintf(reasons + reason_len, "%s", ERR_reason_error_string(e));
     }
 
@@ -253,10 +247,7 @@
     }
 
     *chunk = malloc((len + 1) * sizeof **chunk);
-    if (!*chunk) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!*chunk, -1);
 
     r = nc_read(session, *chunk, len, inact_timeout, ts_act_timeout);
     if (r <= 0) {
@@ -286,10 +277,7 @@
         size = BUFFERSIZE;
     }
     chunk = malloc((size + 1) * sizeof *chunk);
-    if (!chunk) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!chunk, -1);
 
     len = strlen(endtag);
     while (1) {
@@ -305,10 +293,7 @@
             /* get more memory */
             size = size + BUFFERSIZE;
             chunk = nc_realloc(chunk, (size + 1) * sizeof *chunk);
-            if (!chunk) {
-                ERRMEM;
-                return -1;
-            }
+            NC_CHECK_ERRMEM_RET(!chunk, -1);
         }
 
         /* get another character */
@@ -431,11 +416,7 @@
 
             /* realloc message buffer, remember to count terminating null byte */
             data = nc_realloc(data, len + chunk_len + 1);
-            if (!data) {
-                ERRMEM;
-                ret = -1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!data, ret = -1, cleanup);
             memcpy(data + len, chunk, chunk_len);
             len += chunk_len;
             data[len] = '\0';
@@ -951,11 +932,7 @@
         /* <rpc> open */
         count = asprintf(&buf, "<rpc xmlns=\"%s\" message-id=\"%" PRIu64 "\"%s>",
                 NC_NS_BASE, session->opts.client.msgid + 1, attrs ? attrs : "");
-        if (count == -1) {
-            ERRMEM;
-            ret = NC_MSG_ERROR;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(count == -1, ret = NC_MSG_ERROR, cleanup);
         nc_write_clb((void *)&arg, buf, count, 0);
         free(buf);
 
@@ -1114,11 +1091,7 @@
         sid = va_arg(ap, uint32_t *);
 
         count = asprintf(&buf, "<hello xmlns=\"%s\"><capabilities>", NC_NS_BASE);
-        if (count == -1) {
-            ERRMEM;
-            ret = NC_MSG_ERROR;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(count == -1, ret = NC_MSG_ERROR, cleanup);
         nc_write_clb((void *)&arg, buf, count, 0);
         free(buf);
         for (i = 0; capabilities[i]; i++) {
@@ -1128,11 +1101,7 @@
         }
         if (sid) {
             count = asprintf(&buf, "</capabilities><session-id>%u</session-id></hello>", *sid);
-            if (count == -1) {
-                ERRMEM;
-                ret = NC_MSG_ERROR;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(count == -1, ret = NC_MSG_ERROR, cleanup);
             nc_write_clb((void *)&arg, buf, count, 0);
             free(buf);
         } else {
@@ -1194,10 +1163,7 @@
 
         /* allocate some buffer */
         *buf = nc_realloc(*buf, *buf_size);
-        if (!*buf) {
-            ERRMEM;
-            return NULL;
-        }
+        NC_CHECK_ERRMEM_RET(!*buf, NULL);
 
         if (username) {
             ret = getpwnam_r(username, pwd_buf, *buf, *buf_size, &pwd);
diff --git a/src/log_p.h b/src/log_p.h
index 5f3e1d0..c4f6c9e 100644
--- a/src/log_p.h
+++ b/src/log_p.h
@@ -53,6 +53,9 @@
 #define ERRINT ERR(NULL, "%s: internal error (%s:%d).", __func__, __FILE__, __LINE__)
 #define ERRARG(session, ARG) ERR(session, "Invalid argument %s (%s()).", #ARG, __func__)
 
+#define NC_CHECK_ERRMEM_RET(COND, RET) if ((COND)) {ERRMEM; return (RET);}
+#define NC_CHECK_ERRMEM_GOTO(COND, RET, GOTO) if ((COND)) {ERRMEM; RET; goto GOTO;}
+
 #define GETMACRO1(_1, NAME, ...) NAME
 #define GETMACRO2(_1, _2, NAME, ...) NAME
 #define GETMACRO3(_1, _2, _3, NAME, ...) NAME
diff --git a/src/messages_client.c b/src/messages_client.c
index 5cd1165..5008865 100644
--- a/src/messages_client.c
+++ b/src/messages_client.c
@@ -53,10 +53,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_ACT_GENERIC;
     rpc->has_data = 1;
@@ -81,10 +78,7 @@
     NC_CHECK_ARG_RET(NULL, xml_str, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_ACT_GENERIC;
     rpc->has_data = 0;
@@ -111,10 +105,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_GETCONFIG;
     rpc->source = source;
@@ -143,10 +134,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_EDIT;
     rpc->target = target;
@@ -177,10 +165,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_COPY;
     rpc->target = target;
@@ -209,10 +194,7 @@
     NC_CHECK_ARG_RET(NULL, target, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_DELETE;
     rpc->target = target;
@@ -234,10 +216,7 @@
     NC_CHECK_ARG_RET(NULL, target, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_LOCK;
     rpc->target = target;
@@ -253,10 +232,7 @@
     NC_CHECK_ARG_RET(NULL, target, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_UNLOCK;
     rpc->target = target;
@@ -275,10 +251,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_GET;
     if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
@@ -300,10 +273,7 @@
     NC_CHECK_ARG_RET(NULL, session_id, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_KILL;
     rpc->sid = session_id;
@@ -318,10 +288,7 @@
     struct nc_rpc_commit *rpc;
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_COMMIT;
     rpc->confirmed = confirmed;
@@ -347,10 +314,7 @@
     struct nc_rpc *rpc;
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_DISCARD;
 
@@ -363,10 +327,7 @@
     struct nc_rpc_cancel *rpc;
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_CANCEL;
     if (persist_id && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
@@ -392,10 +353,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_VALIDATE;
     rpc->source = source;
@@ -417,10 +375,7 @@
     NC_CHECK_ARG_RET(NULL, identifier, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_GETSCHEMA;
     if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
@@ -455,10 +410,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_SUBSCRIBE;
     if (stream_name && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
@@ -502,10 +454,7 @@
     }
 
     rpc = calloc(1, sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
     rpc->free = (paramtype == NC_PARAMTYPE_CONST ? 0 : 1);
 
     rpc->type = NC_RPC_GETDATA;
@@ -526,16 +475,10 @@
     }
     if (origin_filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
         rpc->origin_filter = malloc(origin_filter_count * sizeof *rpc->origin_filter);
-        if (!rpc->origin_filter) {
-            ERRMEM;
-            goto error;
-        }
+        NC_CHECK_ERRMEM_GOTO(!rpc->origin_filter,; , error);
         for (i = 0; i < origin_filter_count; ++i) {
             rpc->origin_filter[i] = strdup(origin_filter[i]);
-            if (!rpc->origin_filter[i]) {
-                ERRMEM;
-                goto error;
-            }
+            NC_CHECK_ERRMEM_GOTO(!rpc->origin_filter[i],; , error);
             ++rpc->origin_filter_count;
         }
     } else {
@@ -567,10 +510,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_EDITDATA;
     if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
@@ -604,10 +544,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_ESTABLISHSUB;
     if (filter && (paramtype == NC_PARAMTYPE_DUP_AND_FREE)) {
@@ -654,10 +591,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_MODIFYSUB;
     rpc->id = id;
@@ -684,10 +618,7 @@
     NC_CHECK_ARG_RET(NULL, id, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_DELETESUB;
     rpc->id = id;
@@ -703,10 +634,7 @@
     NC_CHECK_ARG_RET(NULL, id, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_KILLSUB;
     rpc->id = id;
@@ -729,10 +657,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_ESTABLISHPUSH;
     if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
@@ -783,10 +708,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_ESTABLISHPUSH;
     if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
@@ -842,10 +764,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_MODIFYPUSH;
     rpc->id = id;
@@ -891,10 +810,7 @@
     }
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_MODIFYPUSH;
     rpc->id = id;
@@ -928,10 +844,7 @@
     NC_CHECK_ARG_RET(NULL, id, NULL);
 
     rpc = malloc(sizeof *rpc);
-    if (!rpc) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!rpc, NULL);
 
     rpc->type = NC_RPC_RESYNCSUB;
     rpc->id = id;
diff --git a/src/messages_server.c b/src/messages_server.c
index 2a98483..b02f5a1 100644
--- a/src/messages_server.c
+++ b/src/messages_server.c
@@ -38,10 +38,7 @@
     struct nc_server_reply *ret;
 
     ret = malloc(sizeof *ret);
-    if (!ret) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!ret, NULL);
 
     ret->type = NC_RPL_OK;
     return ret;
@@ -60,10 +57,7 @@
     }
 
     ret = malloc(sizeof *ret);
-    if (!ret) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!ret, NULL);
 
     ret->type = NC_RPL_DATA;
     ret->wd = wd;
@@ -91,10 +85,7 @@
     NC_CHECK_ARG_RET(NULL, err, NULL);
 
     ret = malloc(sizeof *ret);
-    if (!ret) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!ret, NULL);
 
     ret->type = NC_RPL_ERROR;
     ret->err = err;
@@ -797,10 +788,7 @@
     }
 
     ntf = malloc(sizeof *ntf);
-    if (!ntf) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!ntf, NULL);
 
     if (paramtype == NC_PARAMTYPE_DUP_AND_FREE) {
         ntf->eventtime = strdup(eventtime);
diff --git a/src/server_config.c b/src/server_config.c
index dfed796..82c90ba 100644
--- a/src/server_config.c
+++ b/src/server_config.c
@@ -659,11 +659,7 @@
     char **name;
 
     tmp = realloc(*ptr, (*count + 1) * size);
-    if (!tmp) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!tmp, ret = 1, cleanup);
     *ptr = tmp;
 
     /* set the newly allocated memory to 0 */
@@ -675,11 +671,7 @@
 
     /* and set it's value */
     *name = strdup(key_value);
-    if (!*name) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*name, ret = 1, cleanup);
 
 cleanup:
     return ret;
@@ -907,7 +899,7 @@
         free(cur->fingerprint);
         free(cur);
     }
-    
+
     opts->ctn = NULL;
 }
 
@@ -1214,11 +1206,7 @@
     void *tmp;
 
     tmp = realloc(server_opts.binds, (server_opts.endpt_count + 1) * sizeof *server_opts.binds);
-    if (!tmp) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!tmp, ret = 1, cleanup);
     server_opts.binds = tmp;
     memset(&server_opts.binds[server_opts.endpt_count], 0, sizeof *server_opts.binds);
 
@@ -1335,10 +1323,7 @@
 {
     endpt->ti = NC_TI_LIBSSH;
     endpt->opts.ssh = calloc(1, sizeof(struct nc_server_ssh_opts));
-    if (!endpt->opts.ssh) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!endpt->opts.ssh, 1);
 
     return 0;
 }
@@ -1348,10 +1333,7 @@
 {
     ch_endpt->ti = NC_TI_LIBSSH;
     ch_endpt->opts.ssh = calloc(1, sizeof(struct nc_server_ssh_opts));
-    if (!ch_endpt->opts.ssh) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!ch_endpt->opts.ssh, 1);
 
     return 0;
 }
@@ -1417,10 +1399,7 @@
 {
     endpt->ti = NC_TI_OPENSSL;
     endpt->opts.tls = calloc(1, sizeof *endpt->opts.tls);
-    if (!endpt->opts.tls) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!endpt->opts.tls, 1);
 
     return 0;
 }
@@ -1430,10 +1409,7 @@
 {
     ch_endpt->ti = NC_TI_OPENSSL;
     ch_endpt->opts.tls = calloc(1, sizeof(struct nc_server_tls_opts));
-    if (!ch_endpt->opts.tls) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!ch_endpt->opts.tls, 1);
 
     return 0;
 }
@@ -1580,11 +1556,7 @@
 
         free(bind->address);
         bind->address = strdup(lyd_get_value(node));
-        if (!bind->address) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!bind->address, ret = 1, cleanup);
 
         ret = nc_server_config_set_address_port(endpt, bind, lyd_get_value(node), 0);
         if (ret) {
@@ -1986,10 +1958,7 @@
 {
     free(pubkey->data);
     pubkey->data = strdup(lyd_get_value(node));
-    if (!pubkey->data) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!pubkey->data, 1);
 
     return 0;
 }
@@ -1999,10 +1968,7 @@
 {
     free(hostkey->key.pubkey_data);
     hostkey->key.pubkey_data = strdup(lyd_get_value(node));
-    if (!hostkey->key.pubkey_data) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!hostkey->key.pubkey_data, 1);
 
     return 0;
 }
@@ -2012,10 +1978,7 @@
 {
     free(opts->pubkey_data);
     opts->pubkey_data = strdup(lyd_get_value(node));
-    if (!opts->pubkey_data) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!opts->pubkey_data, 1);
 
     return 0;
 }
@@ -2226,11 +2189,7 @@
         if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
             free(hostkey->key.privkey_data);
             hostkey->key.privkey_data = strdup(lyd_get_value(node));
-            if (!hostkey->key.privkey_data) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!hostkey->key.privkey_data, ret = 1, cleanup);
         } else {
             free(hostkey->key.privkey_data);
             hostkey->key.privkey_data = NULL;
@@ -2245,11 +2204,7 @@
         if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
             free(opts->privkey_data);
             opts->privkey_data = strdup(lyd_get_value(node));
-            if (!opts->privkey_data) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!opts->privkey_data, ret = 1, cleanup);
         } else {
             free(opts->privkey_data);
             opts->privkey_data = NULL;
@@ -2292,11 +2247,7 @@
 
             free(hostkey->ks_ref);
             hostkey->ks_ref = strdup(lyd_get_value(node));
-            if (!hostkey->ks_ref) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!hostkey->ks_ref, ret = 1, cleanup);
         } else if (op == NC_OP_DELETE) {
             free(hostkey->ks_ref);
             hostkey->ks_ref = NULL;
@@ -2458,11 +2409,7 @@
 
             free(auth_client->ts_ref);
             auth_client->ts_ref = strdup(lyd_get_value(node));
-            if (!auth_client->ts_ref) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!auth_client->ts_ref, ret = 1, cleanup);
         } else if (op == NC_OP_DELETE) {
             free(auth_client->ts_ref);
             auth_client->ts_ref = NULL;
@@ -2486,11 +2433,7 @@
 
             free(certs_grp->ts_ref);
             certs_grp->ts_ref = strdup(lyd_get_value(node));
-            if (!certs_grp->ts_ref) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!certs_grp->ts_ref, ret = 1, cleanup);
         } else if (op == NC_OP_DELETE) {
             free(certs_grp->ts_ref);
             certs_grp->ts_ref = NULL;
@@ -2529,11 +2472,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(auth_client->password);
         auth_client->password = strdup(lyd_get_value(node));
-        if (!auth_client->password) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!auth_client->password, ret = 1, cleanup);
     } else {
         free(auth_client->password);
         auth_client->password = NULL;
@@ -2570,11 +2509,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(auth_client->pam_config_name);
         auth_client->pam_config_name = strdup(lyd_get_value(node));
-        if (!auth_client->pam_config_name) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!auth_client->pam_config_name, ret = 1, cleanup);
     } else {
         free(auth_client->pam_config_name);
         auth_client->pam_config_name = NULL;
@@ -2611,11 +2546,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(auth_client->pam_config_dir);
         auth_client->pam_config_dir = strdup(lyd_get_value(node));
-        if (!auth_client->pam_config_dir) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!auth_client->pam_config_dir, ret = 1, cleanup);
     } else {
         free(auth_client->pam_config_dir);
         auth_client->pam_config_dir = NULL;
@@ -2702,46 +2633,26 @@
 
     if (!strncmp(algorithm, "openssh-", 8)) {
         /* if the name starts with openssh, convert it to it's original libssh accepted form */
-        if (asprintf(&alg, "%s@openssh.com", algorithm + 8) == -1) {
-            ERRMEM;
-            alg = NULL;
-            ret = 1;
-            goto cleanup;
-        }
+        ret = asprintf(&alg, "%s@openssh.com", algorithm + 8);
+        NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; alg = NULL, cleanup);
     } else if (!strncmp(algorithm, "libssh-", 7)) {
         /* if the name starts with libssh, convert it to it's original libssh accepted form */
-        if (asprintf(&alg, "%s@libssh.org", algorithm + 7) == -1) {
-            ERRMEM;
-            alg = NULL;
-            ret = 1;
-            goto cleanup;
-        }
+        ret = asprintf(&alg, "%s@libssh.org", algorithm + 7);
+        NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; alg = NULL, cleanup);
     } else {
         alg = strdup(algorithm);
-        if (!alg) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!alg, ret = 1, cleanup);
     }
 
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         if (!*alg_store) {
             /* first call */
             *alg_store = strdup(alg);
-            if (!*alg_store) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!*alg_store, ret = 1, cleanup);
         } else {
             /* +1 because of ',' between algorithms */
-            *alg_store = nc_realloc(*alg_store, strlen(*alg_store) +strlen(alg) + 1 + 1);
-            if (!*alg_store) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            *alg_store = nc_realloc(*alg_store, strlen(*alg_store) + strlen(alg) + 1 + 1);
+            NC_CHECK_ERRMEM_GOTO(!*alg_store, ret = 1, cleanup);
             strcat(*alg_store, ",");
             strcat(*alg_store, alg);
         }
@@ -2966,10 +2877,7 @@
 {
     endpt->ti = NC_TI_UNIX;
     endpt->opts.unixsock = calloc(1, sizeof *endpt->opts.unixsock);
-    if (!endpt->opts.unixsock) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!endpt->opts.unixsock, 1);
 
     /* set default values */
     endpt->opts.unixsock->mode = -1;
@@ -3009,11 +2917,7 @@
 
         opts->address = strdup(lyd_get_value(data));
         bind->address = strdup(lyd_get_value(data));
-        if (!opts->address || !bind->address) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!opts->address || !bind->address, ret = 1, cleanup);
 
         /* silently search for non-mandatory parameters */
         ly_temp_log_options(&log_options);
@@ -3165,10 +3069,7 @@
         /* endpt not found, save the name and try to look it up later */
         free(endpt->referenced_endpt_name);
         endpt->referenced_endpt_name = strdup(endpt_name);
-        if (!endpt->referenced_endpt_name) {
-            ERRMEM;
-            ret = 1;
-        }
+        NC_CHECK_ERRMEM_GOTO(!endpt->referenced_endpt_name, ret = 1, cleanup);
         goto cleanup;
     }
 
@@ -3222,11 +3123,7 @@
         if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
             free(opts->cert_data);
             opts->cert_data = strdup(lyd_get_value(node));
-            if (!opts->cert_data) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!opts->cert_data, ret = 1, cleanup);
         }
     } else if (equal_parent_name(node, 3, "ca-certs") || equal_parent_name(node, 3, "ee-certs")) {
         if (nc_server_config_get_cert(node, &cert)) {
@@ -3237,11 +3134,7 @@
         if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
             free(cert->data);
             cert->data = strdup(lyd_get_value(node));
-            if (!cert->data) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!cert->data, ret = 1, cleanup);
         } else {
             free(cert->data);
             cert->data = NULL;
@@ -3282,11 +3175,7 @@
 
         free(endpt->opts.tls->key_ref);
         endpt->opts.tls->key_ref = strdup(lyd_get_value(node));
-        if (!endpt->opts.tls->key_ref) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!endpt->opts.tls->key_ref, ret = 1, cleanup);
     } else {
         free(endpt->opts.tls->key_ref);
         endpt->opts.tls->key_ref = NULL;
@@ -3351,11 +3240,7 @@
 
             free(opts->cert_ref);
             opts->cert_ref = strdup(lyd_get_value(node));
-            if (!opts->cert_ref) {
-                ERRMEM;
-                ret = 1;
-                goto cleanup;
-            }
+            NC_CHECK_ERRMEM_GOTO(!opts->cert_ref, ret = 1, cleanup);
         } else {
             free(opts->cert_ref);
             opts->cert_ref = NULL;
@@ -3445,11 +3330,7 @@
 
     /* create new ctn */
     new = calloc(1, sizeof *new);
-    if (!new) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!new, ret = 1, cleanup);
 
     /* find the right place for insertion */
     if (!opts->ctn) {
@@ -3475,11 +3356,7 @@
     new->id = id;
     free(new->name);
     new->name = strdup(name);
-    if (!new->name) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!new->name, ret = 1, cleanup);
     new->map_type = m_type;
 
 cleanup:
@@ -3552,11 +3429,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(ctn->fingerprint);
         ctn->fingerprint = strdup(lyd_get_value(node));
-        if (!ctn->fingerprint) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!ctn->fingerprint, ret = 1, cleanup);
     } else {
         free(ctn->fingerprint);
         ctn->fingerprint = NULL;
@@ -3633,11 +3506,7 @@
     void *tmp;
 
     ssl_cipher = malloc(strlen(cipher) + 1);
-    if (!ssl_cipher) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!ssl_cipher, ret = 1, cleanup);
 
     for (i = 0; cipher[i]; i++) {
         if (cipher[i] == '-') {
@@ -3653,19 +3522,11 @@
     if (!opts->ciphers) {
         /* first entry */
         opts->ciphers = strdup(ssl_cipher);
-        if (!opts->ciphers) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!opts->ciphers, ret = 1, cleanup);
     } else {
         /* + 1 because of : between entries */
         tmp = nc_realloc(opts->ciphers, strlen(opts->ciphers) + strlen(ssl_cipher) + 1 + 1);
-        if (!tmp) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!tmp, ret = 1, cleanup);
         opts->ciphers = tmp;
         strcat(opts->ciphers, ":");
         strcat(opts->ciphers, ssl_cipher);
@@ -3755,11 +3616,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(opts->crl_url);
         opts->crl_url = strdup(lyd_get_value(node));
-        if (!opts->crl_url) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!opts->crl_url, ret = 1, cleanup);
     } else if (op == NC_OP_DELETE) {
         free(opts->crl_url);
         opts->crl_url = NULL;
@@ -3796,11 +3653,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(opts->crl_path);
         opts->crl_path = strdup(lyd_get_value(node));
-        if (!opts->crl_path) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!opts->crl_path, ret = 1, cleanup);
     } else if (op == NC_OP_DELETE) {
         free(opts->crl_path);
         opts->crl_path = NULL;
@@ -3929,11 +3782,7 @@
     if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
         free(ch_endpt->address);
         ch_endpt->address = strdup(lyd_get_value(node));
-        if (!ch_endpt->address) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!ch_endpt->address, ret = 1, cleanup);
     } else {
         free(ch_endpt->address);
         ch_endpt->address = NULL;
diff --git a/src/server_config_ks.c b/src/server_config_ks.c
index 75003ff..9540f3d 100644
--- a/src/server_config_ks.c
+++ b/src/server_config_ks.c
@@ -267,10 +267,7 @@
     /* replace the pubkey */
     free(key->pubkey_data);
     key->pubkey_data = strdup(lyd_get_value(node));
-    if (!key->pubkey_data) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!key->pubkey_data, 1);
 
     return 0;
 }
@@ -319,10 +316,7 @@
         /* replace the privkey */
         free(key->privkey_data);
         key->privkey_data = strdup(lyd_get_value(node));
-        if (!key->privkey_data) {
-            ERRMEM;
-            return 1;
-        }
+        NC_CHECK_ERRMEM_RET(!key->privkey_data, 1);
     } else if (op == NC_OP_DELETE) {
         free(key->privkey_data);
         key->privkey_data = NULL;
@@ -384,10 +378,7 @@
         /* replace the cert data */
         free(cert->data);
         cert->data = strdup(lyd_get_value(node));
-        if (!cert->data) {
-            ERRMEM;
-            return 1;
-        }
+        NC_CHECK_ERRMEM_RET(!cert->data, 1);
     }
 
     return 0;
diff --git a/src/server_config_ts.c b/src/server_config_ts.c
index d4004dd..14f684c 100644
--- a/src/server_config_ts.c
+++ b/src/server_config_ts.c
@@ -423,10 +423,7 @@
 
         free(cert->data);
         cert->data = strdup(lyd_get_value(node));
-        if (!cert->data) {
-            ERRMEM;
-            return 1;
-        }
+        NC_CHECK_ERRMEM_RET(!cert->data, 1);
     }
 
     return 0;
@@ -511,11 +508,7 @@
         /* replace the public key */
         free(pkey->data);
         pkey->data = strdup(lyd_get_value(node));
-        if (!pkey->data) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!pkey->data, ret = 1, cleanup);
     }
 
 cleanup:
diff --git a/src/server_config_util.c b/src/server_config_util.c
index 2e8aed1..e02b98f 100644
--- a/src/server_config_util.c
+++ b/src/server_config_util.c
@@ -48,11 +48,7 @@
 
     /* create the path from the format */
     ret = vasprintf(&path, path_fmt, ap);
-    if (ret == -1) {
-        ERRMEM;
-        path = NULL;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; path = NULL, cleanup);
 
     /* create the nodes in the path */
     if (!*tree) {
@@ -94,11 +90,7 @@
 
     /* create the path by appending child to the parent path */
     ret = asprintf(&path, "%s/%s", parent_path, child_name);
-    if (ret == -1) {
-        ERRMEM;
-        path = NULL;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; path = NULL, cleanup);
 
     /* create the nodes in the path */
     if (!*tree) {
@@ -142,11 +134,7 @@
 
     /* create the path from the format */
     ret = vasprintf(&path, path_fmt, ap);
-    if (ret == -1) {
-        ERRMEM;
-        path = NULL;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; path = NULL, cleanup);
 
     /* find the node we want to delete */
     ret = lyd_find_path(*tree, path, 0, &sub);
@@ -188,11 +176,7 @@
 
     /* create the path from the format */
     ret = vasprintf(&path, path_fmt, ap);
-    if (ret == -1) {
-        ERRMEM;
-        path = NULL;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(ret == -1, ret = 1; path = NULL, cleanup);
 
     /* find the node we want to delete */
     ret = lyd_find_path(*tree, path, 0, &sub);
@@ -253,20 +237,12 @@
         /* bin len not divisible by 3, need to add 4 bytes for some padding so that the len is divisible by 4 */
         pub_b64 = malloc((bin_len / 3) * 4 + 4 + 1);
     }
-    if (!pub_b64) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!pub_b64, ret = 1, cleanup);
 
     /* bin to b64 */
     b64_len = EVP_EncodeBlock((unsigned char *)pub_b64, pub_bin, bin_len);
     *pubkey = strndup(pub_b64, b64_len);
-    if (!*pubkey) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*pubkey, ret = 1, cleanup);
 
 cleanup:
     free(pub_b64);
@@ -285,10 +261,7 @@
 
     /* prepare buffer for converting BN to binary */
     bin_tmp = calloc(BN_num_bytes(bn), sizeof *bin_tmp);
-    if (!bin_tmp) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!bin_tmp, 1);
 
     /* convert to binary */
     *bin_len = BN_bn2bin(bn, bin_tmp);
@@ -296,23 +269,13 @@
     /* if the highest bit in the MSB is set a byte with the value 0 has to be prepended */
     if (bin_tmp[0] & 0x80) {
         *bin = malloc(*bin_len + 1);
-        if (!*bin) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
-
+        NC_CHECK_ERRMEM_GOTO(!*bin, ret = 1, cleanup);
         (*bin)[0] = 0;
         memcpy(*bin + 1, bin_tmp, *bin_len);
         (*bin_len)++;
     } else {
         *bin = malloc(*bin_len);
-        if (!*bin) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
-
+        NC_CHECK_ERRMEM_GOTO(!*bin, ret = 1, cleanup);
         memcpy(*bin, bin_tmp, *bin_len);
     }
 
@@ -358,11 +321,7 @@
          */
         bin_len = 4 + alg_name_len + 4 + e_len + 4 + n_len;
         bin = malloc(bin_len);
-        if (!bin) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!bin, ret = 1, cleanup);
 
         /* to network byte order (big endian) */
         alg_name_len_be = htonl(alg_name_len);
@@ -392,11 +351,7 @@
         }
         /* alloc mem for group + 1 for \0 */
         ec_group = malloc(ec_group_len + 1);
-        if (!ec_group) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!ec_group, ret = 1, cleanup);
         /* get the group */
         ret = EVP_PKEY_get_utf8_string_param(pkey, "group", ec_group, ec_group_len + 1, NULL);
         if (!ret) {
@@ -431,11 +386,7 @@
 
         /* prepare buffer for converting p to binary */
         p_bin = malloc(BN_num_bytes(p));
-        if (!p_bin) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!p_bin, ret = 1, cleanup);
         /* convert to binary */
         p_len = BN_bn2bin(p, p_bin);
 
@@ -446,11 +397,7 @@
          */
         bin_len = 4 + alg_name_len + 4 + curve_name_len + 4 + p_len;
         bin = malloc(bin_len);
-        if (!bin) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!bin, ret = 1, cleanup);
 
         /* to network byte order (big endian) */
         alg_name_len_be = htonl(alg_name_len);
@@ -534,11 +481,7 @@
     /* copy the public key without the header and footer */
     *pubkey = strndup(pub_b64 + strlen(NC_SUBJECT_PUBKEY_INFO_HEADER),
             len - strlen(NC_SUBJECT_PUBKEY_INFO_HEADER) - strlen(NC_SUBJECT_PUBKEY_INFO_FOOTER));
-    if (!*pubkey) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*pubkey, ret = 1, cleanup);
 
 cleanup:
     BIO_free(bio);
@@ -589,11 +532,7 @@
     }
 
     c = malloc(cert_len + 1);
-    if (!c) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!c, ret = 1, cleanup);
 
     /* read the cert from bio */
     ret = BIO_read(bio, c, cert_len);
@@ -605,11 +544,7 @@
 
     /* strip the cert of the header and footer */
     *cert = strdup(c + strlen(NC_PEM_CERTIFICATE_HEADER));
-    if (!*cert) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*cert, ret = 1, cleanup);
 
     (*cert)[strlen(*cert) - strlen(NC_PEM_CERTIFICATE_FOOTER)] = '\0';
 
@@ -659,11 +594,7 @@
         }
 
         tmp = realloc(*pubkey, pubkey_len + read + 1);
-        if (!tmp) {
-            ERRMEM;
-            ret = 1;
-            goto cleanup;
-        }
+        NC_CHECK_ERRMEM_GOTO(!tmp, ret = 1, cleanup);
 
         *pubkey = tmp;
         memcpy(*pubkey + pubkey_len, buffer, read);
@@ -897,11 +828,7 @@
     }
 
     *privkey = strndup(priv_b64, len);
-    if (!*privkey) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*privkey, ret = 1, cleanup);
 
 cleanup:
     /* priv_b64 is freed with BIO */
@@ -955,11 +882,7 @@
     }
 
     *privkey = strndup(priv_b64, ret);
-    if (!*privkey) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*privkey, ret = 1, cleanup);
 
     /* ok */
     ret = 0;
@@ -1019,11 +942,7 @@
 
     /* strip private key's header and footer */
     *privkey = strdup(priv + strlen(NC_PKCS8_PRIVKEY_HEADER));
-    if (!*privkey) {
-        ERRMEM;
-        ret = 1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*privkey, ret = 1, cleanup);
     (*privkey)[strlen(*privkey) - strlen(NC_PKCS8_PRIVKEY_FOOTER)] = '\0';
 
 cleanup:
@@ -1414,12 +1333,8 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, path, config, 1);
 
-    if (asprintf(&tree_path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/libnetconf2-netconf-server:unix-socket", endpt_name) == -1) {
-        ERRMEM;
-        tree_path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&tree_path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/libnetconf2-netconf-server:unix-socket", endpt_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, tree_path = NULL; ret = 1, cleanup);
 
     /* path to unix socket */
     ret = nc_server_config_append(ctx, tree_path, "path", path, config);
@@ -1575,13 +1490,8 @@
     NC_CHECK_ARG_RET(NULL, ctx, ch_client_name, config, 1);
 
     /* prepared the path */
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
-            "netconf-client[name='%s']/reconnect-strategy", ch_client_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/reconnect-strategy", ch_client_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     if (start_with) {
         /* get string value from enum */
diff --git a/src/server_config_util_ssh.c b/src/server_config_util_ssh.c
index d19dc77..00cfe74 100644
--- a/src/server_config_util_ssh.c
+++ b/src/server_config_util_ssh.c
@@ -102,13 +102,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, hostkey_name, privkey_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
-            "server-identity/host-key[name='%s']/public-key", endpt_name, hostkey_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
+            "server-identity/host-key[name='%s']/public-key", endpt_name, hostkey_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_hostkey(ctx, path, privkey_path, pubkey_path, config);
     if (ret) {
@@ -130,14 +126,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, hostkey_name, privkey_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
             "netconf-client[name='%s']/endpoints/endpoint[name='%s']/ssh/ssh-server-parameters/server-identity/"
-            "host-key[name='%s']/public-key", client_name, endpt_name, hostkey_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "host-key[name='%s']/public-key", client_name, endpt_name, hostkey_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_hostkey(ctx, path, privkey_path, pubkey_path, config);
     if (ret) {
@@ -296,14 +288,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, user_name, pubkey_name, pubkey_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/"
             "ssh-server-parameters/client-authentication/users/user[name='%s']/public-keys/inline-definition/"
-            "public-key[name='%s']", endpt_name, user_name, pubkey_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "public-key[name='%s']", endpt_name, user_name, pubkey_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_pubkey(ctx, path, pubkey_path, config);
     if (ret) {
@@ -333,15 +321,11 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, user_name, pubkey_name, pubkey_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
             "endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/"
             "users/user[name='%s']/public-keys/inline-definition/public-key[name='%s']", client_name,
-            endpt_name, user_name, pubkey_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            endpt_name, user_name, pubkey_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_pubkey(ctx, path, pubkey_path, config);
     if (ret) {
@@ -445,13 +429,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, user_name, password, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
-            "client-authentication/users/user[name='%s']", endpt_name, user_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
+            "client-authentication/users/user[name='%s']", endpt_name, user_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_password(ctx, path, password, config);
     if (ret) {
@@ -473,14 +453,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, user_name, password, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
             "endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/"
-            "users/user[name='%s']", client_name, endpt_name, user_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "users/user[name='%s']", client_name, endpt_name, user_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_password(ctx, path, password, config);
     if (ret) {
@@ -544,14 +520,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, user_name, pam_config_name, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/ssh/ssh-server-parameters/"
             "client-authentication/users/user[name='%s']/"
-            "libnetconf2-netconf-server:keyboard-interactive", endpt_name, user_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "libnetconf2-netconf-server:keyboard-interactive", endpt_name, user_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_interactive(ctx, path, pam_config_name, pam_config_dir, config);
     if (ret) {
@@ -573,14 +545,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, user_name, pam_config_name, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
             "endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/users/user[name='%s']/"
-            "libnetconf2-netconf-server:keyboard-interactive", client_name, endpt_name, user_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "libnetconf2-netconf-server:keyboard-interactive", client_name, endpt_name, user_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_ssh_user_interactive(ctx, path, pam_config_name, pam_config_dir, config);
     if (ret) {
diff --git a/src/server_config_util_tls.c b/src/server_config_util_tls.c
index 0ee6b06..66b2559 100644
--- a/src/server_config_util_tls.c
+++ b/src/server_config_util_tls.c
@@ -111,13 +111,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, privkey_path, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/"
-            "tls/tls-server-parameters/server-identity/certificate", endpt_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/"
+            "tls/tls-server-parameters/server-identity/certificate", endpt_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_server_cert(ctx, path, privkey_path, pubkey_path,
             cert_path, config);
@@ -149,14 +145,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, privkey_path, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/"
             "netconf-client[name='%s']/endpoints/endpoint[name='%s']/tls/tls-server-parameters/server-identity/"
-            "certificate", client_name, endpt_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "certificate", client_name, endpt_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_server_cert(ctx, path, privkey_path, pubkey_path,
             cert_path, config);
@@ -218,13 +210,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, asym_key_ref, cert_ref, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/"
-            "tls/tls-server-parameters/server-identity/certificate", endpt_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/"
+            "tls/tls-server-parameters/server-identity/certificate", endpt_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_keystore_ref(ctx, path, asym_key_ref, cert_ref, config);
     if (ret) {
@@ -254,13 +242,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, asym_key_ref, cert_ref, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
-            "endpoint[name='%s']/tls/tls-server-parameters/server-identity/certificate", client_name, endpt_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
+            "endpoint[name='%s']/tls/tls-server-parameters/server-identity/certificate", client_name, endpt_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_keystore_ref(ctx, path, asym_key_ref, cert_ref, config);
     if (ret) {
@@ -317,13 +301,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, cert_name, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/tls-server-parameters/"
-            "client-authentication/ee-certs/inline-definition/certificate[name='%s']", endpt_name, cert_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/tls-server-parameters/"
+            "client-authentication/ee-certs/inline-definition/certificate[name='%s']", endpt_name, cert_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_client_cert(ctx, path, cert_path, config);
     if (ret) {
@@ -368,14 +348,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, cert_name, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
             "endpoints/endpoint[name='%s']/tls/tls-server-parameters/client-authentication/ee-certs/"
-            "inline-definition/certificate[name='%s']", client_name, endpt_name, cert_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "inline-definition/certificate[name='%s']", client_name, endpt_name, cert_name) == -1;
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_client_cert(ctx, path, cert_path, config);
     if (ret) {
@@ -494,13 +470,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, cert_name, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/tls-server-parameters/"
-            "client-authentication/ca-certs/inline-definition/certificate[name='%s']", endpt_name, cert_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/tls-server-parameters/"
+            "client-authentication/ca-certs/inline-definition/certificate[name='%s']", endpt_name, cert_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_client_cert(ctx, path, cert_path, config);
     if (ret) {
@@ -545,14 +517,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, cert_name, cert_path, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
             "endpoints/endpoint[name='%s']/tls/tls-server-parameters/client-authentication/ca-certs/"
-            "inline-definition/certificate[name='%s']", client_name, endpt_name, cert_name) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "inline-definition/certificate[name='%s']", client_name, endpt_name, cert_name);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_client_cert(ctx, path, cert_path, config);
     if (ret) {
@@ -732,13 +700,9 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, endpt_name, id, name, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/netconf-server-parameters/"
-            "client-identity-mappings/cert-to-name[id='%u']", endpt_name, id) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoint[name='%s']/tls/netconf-server-parameters/"
+            "client-identity-mappings/cert-to-name[id='%u']", endpt_name, id);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_ctn(ctx, path, fingerprint, map_type, name, config);
     if (ret) {
@@ -774,14 +738,10 @@
 
     NC_CHECK_ARG_RET(NULL, ctx, client_name, endpt_name, id, name, config, 1);
 
-    if (asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
+    ret = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/"
             "endpoints/endpoint[name='%s']/tls/netconf-server-parameters/client-identity-mappings/"
-            "cert-to-name[id='%u']", client_name, endpt_name, id) == -1) {
-        ERRMEM;
-        path = NULL;
-        ret = 1;
-        goto cleanup;
-    }
+            "cert-to-name[id='%u']", client_name, endpt_name, id);
+    NC_CHECK_ERRMEM_GOTO(ret == -1, path = NULL; ret = 1, cleanup);
 
     ret = _nc_server_config_add_tls_ctn(ctx, path, fingerprint, map_type, name, config);
     if (ret) {
diff --git a/src/session.c b/src/session.c
index 78cec17..2aed66e 100644
--- a/src/session.c
+++ b/src/session.c
@@ -136,10 +136,7 @@
     nl_count = strlen(base64) / 64;
     remainder = strlen(base64) - 64 * nl_count;
     b64 = calloc(strlen(base64) + nl_count + 1, 1);
-    if (!b64) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!b64, -1);
 
     for (i = 0; i < nl_count; i++) {
         /* copy 64 bytes and add a NL */
@@ -1080,10 +1077,7 @@
     NC_CHECK_ARG_RET(NULL, ctx, NULL);
 
     cpblts = malloc(size * sizeof *cpblts);
-    if (!cpblts) {
-        ERRMEM;
-        goto error;
-    }
+    NC_CHECK_ERRMEM_GOTO(!cpblts,; , error);
     cpblts[0] = strdup("urn:ietf:params:netconf:base:1.0");
     cpblts[1] = strdup("urn:ietf:params:netconf:base:1.1");
     count = 2;
@@ -1185,16 +1179,10 @@
             /* get content-id */
             if (server_opts.content_id_clb) {
                 yl_content_id = server_opts.content_id_clb(server_opts.content_id_data);
-                if (!yl_content_id) {
-                    ERRMEM;
-                    goto error;
-                }
+                NC_CHECK_ERRMEM_GOTO(!yl_content_id,; , error);
             } else {
                 yl_content_id = malloc(11);
-                if (!yl_content_id) {
-                    ERRMEM;
-                    goto error;
-                }
+                NC_CHECK_ERRMEM_GOTO(!yl_content_id,; , error);
                 sprintf(yl_content_id, "%u", ly_ctx_get_change_count(ctx));
             }
 
@@ -1301,10 +1289,7 @@
         }
         /* last item remains NULL */
         *list = calloc(i + 1, sizeof **list);
-        if (!*list) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!*list, -1);
         i = 0;
     }
 
@@ -1334,10 +1319,7 @@
         /* store capabilities */
         if (list) {
             (*list)[i] = strndup(cpb_start, cpb_end - cpb_start);
-            if (!(*list)[i]) {
-                ERRMEM;
-                return -1;
-            }
+            NC_CHECK_ERRMEM_RET(!(*list)[i], -1);
             i++;
         }
     }
@@ -1360,10 +1342,7 @@
     if (session->side == NC_CLIENT) {
         /* client side hello - send only NETCONF base capabilities */
         cpblts = malloc(3 * sizeof *cpblts);
-        if (!cpblts) {
-            ERRMEM;
-            return NC_MSG_ERROR;
-        }
+        NC_CHECK_ERRMEM_RET(!cpblts, NC_MSG_ERROR);
         cpblts[0] = strdup("urn:ietf:params:netconf:base:1.0");
         cpblts[1] = strdup("urn:ietf:params:netconf:base:1.1");
         cpblts[2] = NULL;
diff --git a/src/session_client.c b/src/session_client.c
index 047d6ed..c45d764 100644
--- a/src/session_client.c
+++ b/src/session_client.c
@@ -279,10 +279,7 @@
 
     if (path) {
         client_opts.schema_searchpath = strdup(path);
-        if (!client_opts.schema_searchpath) {
-            ERRMEM;
-            return 1;
-        }
+        NC_CHECK_ERRMEM_RET(!client_opts.schema_searchpath, 1);
     } else {
         client_opts.schema_searchpath = NULL;
     }
@@ -920,11 +917,7 @@
     }
 
     (*result) = calloc(modules->count + 1, sizeof **result);
-    if (!(*result)) {
-        ERRMEM;
-        ret = -1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!(*result), ret = -1, cleanup);
 
     for (u = 0; u < modules->count; ++u) {
         submodules_count = 0;
@@ -947,13 +940,7 @@
                 (*result)[u].implemented = !strcmp(lyd_get_value(iter), "implement");
             } else if (!strcmp(iter->schema->name, "feature")) {
                 (*result)[u].features = nc_realloc((*result)[u].features, (feature_count + 2) * sizeof *(*result)[u].features);
-                if (!(*result)[u].features) {
-                    ERRMEM;
-                    free_module_info(*result);
-                    *result = NULL;
-                    ret = -1;
-                    goto cleanup;
-                }
+                NC_CHECK_ERRMEM_GOTO(!(*result)[u].features, free_module_info(*result); *result = NULL; ret = -1, cleanup);
                 (*result)[u].features[feature_count] = strdup(lyd_get_value(iter));
                 (*result)[u].features[feature_count + 1] = NULL;
                 ++feature_count;
@@ -964,25 +951,18 @@
 
         if (submodules_count) {
             (*result)[u].submodules = calloc(submodules_count + 1, sizeof *(*result)[u].submodules);
-            if (!(*result)[u].submodules) {
-                ERRMEM;
-                free_module_info(*result);
-                *result = NULL;
-                ret = -1;
-                goto cleanup;
-            } else {
-                v = 0;
-                LY_LIST_FOR(lyd_child(modules->dnodes[u]), iter) {
-                    mod = modules->dnodes[u]->schema->module;
-                    if ((mod == iter->schema->module) && !strcmp(iter->schema->name, "submodule")) {
-                        LY_LIST_FOR(lyd_child(iter), child) {
-                            if (mod != child->schema->module) {
-                                continue;
-                            } else if (!strcmp(child->schema->name, "name")) {
-                                (*result)[u].submodules[v].name = strdup(lyd_get_value(child));
-                            } else if (!strcmp(child->schema->name, "revision")) {
-                                (*result)[u].submodules[v].revision = strdup(lyd_get_value(child));
-                            }
+            NC_CHECK_ERRMEM_GOTO(!(*result)[u].submodules, free_module_info(*result); *result = NULL; ret = -1, cleanup);
+            v = 0;
+            LY_LIST_FOR(lyd_child(modules->dnodes[u]), iter) {
+                mod = modules->dnodes[u]->schema->module;
+                if ((mod == iter->schema->module) && !strcmp(iter->schema->name, "submodule")) {
+                    LY_LIST_FOR(lyd_child(iter), child) {
+                        if (mod != child->schema->module) {
+                            continue;
+                        } else if (!strcmp(child->schema->name, "name")) {
+                            (*result)[u].submodules[v].name = strdup(lyd_get_value(child));
+                        } else if (!strcmp(child->schema->name, "revision")) {
+                            (*result)[u].submodules[v].revision = strdup(lyd_get_value(child));
                         }
                     }
                 }
@@ -1012,10 +992,7 @@
 
     for (u = 0; cpblts[u]; ++u) {}
     (*result) = calloc(u + 1, sizeof **result);
-    if (!(*result)) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!(*result), -1);
 
     for (u = v = 0; cpblts[u]; ++u) {
         module_cpblt = strstr(cpblts[u], "module=");
@@ -1394,10 +1371,7 @@
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!session, NULL);
     session->status = NC_STATUS_STARTING;
 
     /* transport specific data */
@@ -1462,10 +1436,7 @@
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        goto fail;
-    }
+    NC_CHECK_ERRMEM_GOTO(!session,; , fail);
     session->status = NC_STATUS_STARTING;
 
     /* transport specific data */
@@ -1487,10 +1458,7 @@
     }
     username = strdup(pw->pw_name);
     free(buf);
-    if (!username) {
-        ERRMEM;
-        goto fail;
-    }
+    NC_CHECK_ERRMEM_GOTO(!username,; , fail);
     session->username = username;
 
     /* NETCONF handshake */
@@ -1532,10 +1500,7 @@
 
     str_len = (saddr->sa_family == AF_INET) ? INET_ADDRSTRLEN : INET6_ADDRSTRLEN;
     *str_ip = malloc(str_len);
-    if (!*str_ip) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!(*str_ip), -1);
 
     if (saddr->sa_family == AF_INET) {
         addr = &((struct sockaddr_in *)saddr)->sin_addr;
@@ -2110,11 +2075,7 @@
             cont_ptr = &((*cont_ptr)->next);
         }
         *cont_ptr = malloc(sizeof **cont_ptr);
-        if (!*cont_ptr) {
-            ERRMEM;
-            ret = NC_MSG_ERROR;
-            goto cleanup_unlock;
-        }
+        NC_CHECK_ERRMEM_GOTO(!*cont_ptr, ret = NC_MSG_ERROR, cleanup_unlock);
         (*cont_ptr)->msg = msg;
         msg = NULL;
         (*cont_ptr)->type = ret;
@@ -2479,10 +2440,8 @@
     }
 
     ntarg = malloc(sizeof *ntarg);
-    if (!ntarg) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!ntarg, -1);
+
     ntarg->session = session;
     ntarg->notif_clb = notif_clb;
     ntarg->user_data = user_data;
diff --git a/src/session_client_ssh.c b/src/session_client_ssh.c
index 50eb1d2..02a8c7a 100644
--- a/src/session_client_ssh.c
+++ b/src/session_client_ssh.c
@@ -333,12 +333,14 @@
 
     if ((srv_pubkey_type != SSH_KEYTYPE_UNKNOWN) && (srv_pubkey_type != SSH_KEYTYPE_RSA1)) {
         if (srv_pubkey_type == SSH_KEYTYPE_DSS) {
-            /* TODO else branch? */
             ret = sshauth_hostkey_hash_dnssec_check(hostname, hash_sha1, 2, 1);
         } else if (srv_pubkey_type == SSH_KEYTYPE_RSA) {
             ret = sshauth_hostkey_hash_dnssec_check(hostname, hash_sha1, 1, 1);
         } else if (srv_pubkey_type == SSH_KEYTYPE_ECDSA) {
             ret = sshauth_hostkey_hash_dnssec_check(hostname, hash_sha1, 3, 1);
+        } else {
+            /* other key types not supported */
+            ret = 1;
         }
 
         /* DNSSEC SSHFP check successful, that's enough */
@@ -515,10 +517,7 @@
     FILE *in = NULL, *out = NULL;
 
     buf = malloc(buflen * sizeof *buf);
-    if (!buf) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!buf, NULL);
 
     if (!(in = nc_open_in(0, &oldterm))) {
         goto error;
@@ -538,10 +537,7 @@
         if (len >= buflen - 1) {
             buflen *= 2;
             buf = nc_realloc(buf, buflen * sizeof *buf);
-            if (!buf) {
-                ERRMEM;
-                goto error;
-            }
+            NC_CHECK_ERRMEM_GOTO(!buf,; , error);
         }
         buf[len++] = (char)c;
     }
@@ -570,10 +566,7 @@
     FILE *in = NULL, *out = NULL;
 
     buf = malloc(buflen * sizeof *buf);
-    if (!buf) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!buf, NULL);
 
     if (!(in = nc_open_in(echo, &oldterm))) {
         goto error;
@@ -601,10 +594,7 @@
         if (cur_len >= buflen - 1) {
             buflen *= 2;
             buf = nc_realloc(buf, buflen * sizeof *buf);
-            if (!buf) {
-                ERRMEM;
-                goto error;
-            }
+            NC_CHECK_ERRMEM_GOTO(!buf,; , error);
         }
         buf[cur_len++] = (char)c;
     }
@@ -633,10 +623,7 @@
     FILE *in = NULL, *out = NULL;
 
     buf = malloc(buflen * sizeof *buf);
-    if (!buf) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!buf, NULL);
 
     if (!(in = nc_open_in(0, &oldterm))) {
         goto error;
@@ -656,10 +643,7 @@
         if (len >= buflen - 1) {
             buflen *= 2;
             buf = nc_realloc(buf, buflen * sizeof *buf);
-            if (!buf) {
-                ERRMEM;
-                goto error;
-            }
+            NC_CHECK_ERRMEM_GOTO(!buf,; , error);
         }
         buf[len++] = (char)c;
     }
@@ -689,10 +673,7 @@
     }
 
     ssh_opts.knownhosts_path = strdup(path);
-    if (!ssh_opts.knownhosts_path) {
-        ERRMEM;
-        return 1;
-    }
+    NC_CHECK_ERRMEM_RET(!ssh_opts.knownhosts_path, 1);
 
     return 0;
 }
@@ -897,18 +878,12 @@
     /* add the keys */
     ++opts->key_count;
     opts->keys = nc_realloc(opts->keys, opts->key_count * sizeof *opts->keys);
-    if (!opts->keys) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!opts->keys, -1);
     opts->keys[opts->key_count - 1].pubkey_path = strdup(pub_key);
     opts->keys[opts->key_count - 1].privkey_path = strdup(priv_key);
     opts->keys[opts->key_count - 1].privkey_crypt = 0;
 
-    if (!opts->keys[opts->key_count - 1].pubkey_path || !opts->keys[opts->key_count - 1].privkey_path) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!opts->keys[opts->key_count - 1].pubkey_path || !opts->keys[opts->key_count - 1].privkey_path, -1);
 
     /* check encryption */
     if ((key = fopen(priv_key, "r"))) {
@@ -962,10 +937,7 @@
     }
     if (opts->key_count) {
         opts->keys = nc_realloc(opts->keys, opts->key_count * sizeof *opts->keys);
-        if (!opts->keys) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->keys, -1);
     } else {
         free(opts->keys);
         opts->keys = NULL;
@@ -1101,10 +1073,7 @@
     }
     if (username) {
         opts->username = strdup(username);
-        if (!opts->username) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->username, -1);
     } else {
         opts->username = NULL;
     }
@@ -1519,10 +1488,7 @@
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!session, NULL);
     session->status = NC_STATUS_STARTING;
     session->ti_type = NC_TI_LIBSSH;
     session->ti.libssh.session = ssh_session;
@@ -1538,10 +1504,7 @@
 
         /* remember host */
         host = strdup("localhost");
-        if (!host) {
-            ERRMEM;
-            goto fail;
-        }
+        NC_CHECK_ERRMEM_GOTO(!host,; , fail);
         ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_HOST, host);
 
         /* create and connect socket */
@@ -1578,10 +1541,7 @@
             } else {
                 username = strdup(opts->username);
             }
-            if (!username) {
-                ERRMEM;
-                goto fail;
-            }
+            NC_CHECK_ERRMEM_GOTO(!username,; , fail);
             ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_USER, username);
         }
 
@@ -1671,24 +1631,15 @@
     if (ssh_opts.knownhosts_path) {
         /* known_hosts file path was set so use it */
         known_hosts_path = strdup(ssh_opts.knownhosts_path);
-        if (!known_hosts_path) {
-            ERRMEM;
-            goto fail;
-        }
+        NC_CHECK_ERRMEM_GOTO(!known_hosts_path,; , fail);
     } else if (pw) {
         /* path not set explicitly, but current user's username found in /etc/passwd, so create the path */
-        if (asprintf(&known_hosts_path, "%s/.ssh/known_hosts", pw->pw_dir) == -1) {
-            ERRMEM;
-            goto fail;
-        }
+        NC_CHECK_ERRMEM_GOTO(asprintf(&known_hosts_path, "%s/.ssh/known_hosts", pw->pw_dir) == -1,; , fail);
     }
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        goto fail;
-    }
+    NC_CHECK_ERRMEM_GOTO(!session,; , fail);
     session->status = NC_STATUS_STARTING;
 
     /* transport-specific data */
@@ -1773,10 +1724,7 @@
 
     /* prepare session structure */
     new_session = nc_new_session(NC_CLIENT, 1);
-    if (!new_session) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!new_session, NULL);
     new_session->status = NC_STATUS_STARTING;
 
     /* share some parameters including the IO lock (we are using one socket for both sessions) */
diff --git a/src/session_client_tls.c b/src/session_client_tls.c
index 1d4aa12..bf5dcdb 100644
--- a/src/session_client_tls.c
+++ b/src/session_client_tls.c
@@ -168,17 +168,11 @@
     free(opts->key_path);
 
     opts->cert_path = strdup(client_cert);
-    if (!opts->cert_path) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!opts->cert_path, -1);
 
     if (client_key) {
         opts->key_path = strdup(client_key);
-        if (!opts->key_path) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->key_path, -1);
     } else {
         opts->key_path = NULL;
     }
@@ -241,20 +235,14 @@
 
     if (ca_file) {
         opts->ca_file = strdup(ca_file);
-        if (!opts->ca_file) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->ca_file, -1);
     } else {
         opts->ca_file = NULL;
     }
 
     if (ca_dir) {
         opts->ca_dir = strdup(ca_dir);
-        if (!opts->ca_dir) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->ca_dir, -1);
     } else {
         opts->ca_dir = NULL;
     }
@@ -317,20 +305,14 @@
 
     if (crl_file) {
         opts->crl_file = strdup(crl_file);
-        if (!opts->crl_file) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->crl_file, -1);
     } else {
         opts->crl_file = NULL;
     }
 
     if (crl_dir) {
         opts->crl_dir = strdup(crl_dir);
-        if (!opts->crl_dir) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!opts->crl_dir, -1);
     } else {
         opts->crl_dir = NULL;
     }
@@ -567,10 +549,7 @@
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!session, NULL);
     session->status = NC_STATUS_STARTING;
 
     /* fill the session */
@@ -649,10 +628,7 @@
 
     /* prepare session structure */
     session = nc_new_session(NC_CLIENT, 0);
-    if (!session) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!session, NULL);
     session->status = NC_STATUS_STARTING;
     session->ti_type = NC_TI_OPENSSL;
     session->ti.tls = tls;
diff --git a/src/session_server.c b/src/session_server.c
index be53450..30db040 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -447,10 +447,7 @@
         return 0;
     }
 
-    if (!(*host = strdup(sun_path))) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!(*host = strdup(sun_path)), -1);
 
     return 0;
 }
@@ -467,10 +464,7 @@
 sock_host_inet(const struct sockaddr_in *addr, char **host, uint16_t *port)
 {
     *host = malloc(INET_ADDRSTRLEN);
-    if (!(*host)) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!(*host), -1);
 
     if (!inet_ntop(AF_INET, &addr->sin_addr, *host, INET_ADDRSTRLEN)) {
         ERR(NULL, "inet_ntop failed (%s).", strerror(errno));
@@ -496,10 +490,7 @@
 sock_host_inet6(const struct sockaddr_in6 *addr, char **host, uint16_t *port)
 {
     *host = malloc(INET6_ADDRSTRLEN);
-    if (!(*host)) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!(*host), -1);
 
     if (!inet_ntop(AF_INET6, &addr->sin6_addr, *host, INET6_ADDRSTRLEN)) {
         ERR(NULL, "inet_ntop failed (%s).", strerror(errno));
@@ -525,10 +516,7 @@
     int ret, client_sock, sock = -1, flags;
 
     pfd = malloc(bind_count * sizeof *pfd);
-    if (!pfd) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!pfd, -1);
 
     /* LOCK */
     pthread_mutex_lock(bind_lock);
@@ -938,10 +926,7 @@
     }
 
     mem = realloc(server_opts.capabilities, (server_opts.capabilities_count + 1) * sizeof *server_opts.capabilities);
-    if (!mem) {
-        ERRMEM;
-        return EXIT_FAILURE;
-    }
+    NC_CHECK_ERRMEM_RET(!mem, EXIT_FAILURE);
     server_opts.capabilities = mem;
 
     server_opts.capabilities[server_opts.capabilities_count] = strdup(value);
@@ -980,10 +965,7 @@
 
     /* prepare session structure */
     *session = nc_new_session(NC_SERVER, 0);
-    if (!(*session)) {
-        ERRMEM;
-        return NC_MSG_ERROR;
-    }
+    NC_CHECK_ERRMEM_RET(!(*session), NC_MSG_ERROR);
     (*session)->status = NC_STATUS_STARTING;
 
     /* transport specific data */
@@ -1178,10 +1160,7 @@
     struct nc_pollsession *ps;
 
     ps = calloc(1, sizeof(struct nc_pollsession));
-    if (!ps) {
-        ERRMEM;
-        return NULL;
-    }
+    NC_CHECK_ERRMEM_RET(!ps, NULL);
     pthread_cond_init(&ps->cond, NULL);
     pthread_mutex_init(&ps->lock, NULL);
 
@@ -1427,11 +1406,7 @@
     }
 
     *rpc = calloc(1, sizeof **rpc);
-    if (!*rpc) {
-        ERRMEM;
-        ret = NC_PSPOLL_ERROR;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!*rpc, ret = NC_PSPOLL_ERROR, cleanup);
 
     /* parse the RPC */
     if (!lyd_parse_op(session->ctx, NULL, msg, LYD_XML, LYD_TYPE_RPC_NETCONF, &(*rpc)->envp, &(*rpc)->rpc)) {
@@ -2128,13 +2103,7 @@
     sock = ret;
 
     *session = nc_new_session(NC_SERVER, 0);
-    if (!(*session)) {
-        ERRMEM;
-        close(sock);
-        free(host);
-        msgtype = NC_MSG_ERROR;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!(*session), close(sock); free(host); msgtype = NC_MSG_ERROR, cleanup);
     (*session)->status = NC_STATUS_STARTING;
     (*session)->ctx = (struct ly_ctx *)ctx;
     (*session)->flags = NC_SESSION_SHAREDCTX;
@@ -2319,13 +2288,7 @@
 
     /* create session */
     *session = nc_new_session(NC_SERVER, 0);
-    if (!(*session)) {
-        ERRMEM;
-        close(sock);
-        free(ip_host);
-        msgtype = NC_MSG_ERROR;
-        goto fail;
-    }
+    NC_CHECK_ERRMEM_GOTO(!(*session), close(sock); free(ip_host); msgtype = NC_MSG_ERROR, fail);
     (*session)->status = NC_STATUS_STARTING;
     (*session)->ctx = (struct ly_ctx *)ctx;
     (*session)->flags = NC_SESSION_SHAREDCTX | NC_SESSION_CALLHOME;
@@ -2763,10 +2726,7 @@
     }
 
     arg = malloc(sizeof *arg);
-    if (!arg) {
-        ERRMEM;
-        return -1;
-    }
+    NC_CHECK_ERRMEM_RET(!arg, -1);
     arg->client_name = strdup(client_name);
     if (!arg->client_name) {
         ERRMEM;
diff --git a/src/session_server_ssh.c b/src/session_server_ssh.c
index d4bb528..402c91a 100644
--- a/src/session_server_ssh.c
+++ b/src/session_server_ssh.c
@@ -351,11 +351,7 @@
     *resp = calloc(n_requests, sizeof **resp);
     prompts = calloc(n_requests, sizeof *prompts);
     echo = calloc(n_requests, sizeof *echo);
-    if (!(*resp) || !prompts || !echo) {
-        ERRMEM;
-        r = PAM_BUF_ERR;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!(*resp) || !prompts || !echo, r = PAM_BUF_ERR, cleanup);
 
     /* set the prompts for the user */
     j = 0;
@@ -814,10 +810,7 @@
     } else {
         /* additional channel subsystem request, new session is ready as far as SSH is concerned */
         new_session = nc_new_session(NC_SERVER, 1);
-        if (!new_session) {
-            ERRMEM;
-            return -1;
-        }
+        NC_CHECK_ERRMEM_RET(!new_session, -1);
 
         /* insert the new session */
         if (!session->ti.libssh.next) {
diff --git a/src/session_server_tls.c b/src/session_server_tls.c
index a48ae45..2dc68df 100644
--- a/src/session_server_tls.c
+++ b/src/session_server_tls.c
@@ -203,10 +203,7 @@
             *strchr(common_name, '/') = '\0';
         }
         *username = strdup(common_name);
-        if (!*username) {
-            ERRMEM;
-            return 1;
-        }
+        NC_CHECK_ERRMEM_RET(!*username, 1);
         free(subject);
     } else {
         /* retrieve subjectAltName's rfc822Name (email), dNSName and iPAddress values */
@@ -224,10 +221,7 @@
             if (((map_type == NC_TLS_CTN_SAN_ANY) || (map_type == NC_TLS_CTN_SAN_RFC822_NAME)) &&
                     (san_name->type == GEN_EMAIL)) {
                 *username = strdup((char *)ASN1_STRING_get0_data(san_name->d.rfc822Name));
-                if (!*username) {
-                    ERRMEM;
-                    return 1;
-                }
+                NC_CHECK_ERRMEM_RET(!*username, 1);
                 break;
             }
 
@@ -235,10 +229,7 @@
             if (((map_type == NC_TLS_CTN_SAN_ANY) || (map_type == NC_TLS_CTN_SAN_DNS_NAME)) &&
                     (san_name->type == GEN_DNS)) {
                 *username = strdup((char *)ASN1_STRING_get0_data(san_name->d.dNSName));
-                if (!*username) {
-                    ERRMEM;
-                    return 1;
-                }
+                NC_CHECK_ERRMEM_RET(!*username, 1);
                 break;
             }
 
@@ -300,17 +291,15 @@
 {
     char *digest_md5 = NULL, *digest_sha1 = NULL, *digest_sha224 = NULL;
     char *digest_sha256 = NULL, *digest_sha384 = NULL, *digest_sha512 = NULL;
-    unsigned char *buf = malloc(64);
+    unsigned char *buf;
     unsigned int buf_len = 64;
     int ret = 0;
     struct nc_ctn *ctn;
     NC_TLS_CTN_MAPTYPE map_type;
     char *username = NULL;
 
-    if (!buf) {
-        ERRMEM;
-        return -1;
-    }
+    buf = malloc(buf_len);
+    NC_CHECK_ERRMEM_RET(!buf, -1);
 
     if (!session || !cert) {
         free(buf);
@@ -456,11 +445,7 @@
             if (map_type == NC_TLS_CTN_SPECIFIED) {
                 /* specified -> get username from the ctn entry */
                 session->username = strdup(ctn->name);
-                if (!session->username) {
-                    ERRMEM;
-                    ret = -1;
-                    goto cleanup;
-                }
+                NC_CHECK_ERRMEM_GOTO(!session->username, ret = -1, cleanup);
             } else {
                 /* try to get the username from the cert with this ctn's map type */
                 ret = nc_tls_ctn_get_username_from_cert(session->opts.server.client_cert, map_type, &username);
@@ -512,11 +497,7 @@
     char *cp;
 
     store_ctx = X509_STORE_CTX_new();
-    if (!store_ctx) {
-        ERRMEM;
-        ret = -1;
-        goto cleanup;
-    }
+    NC_CHECK_ERRMEM_GOTO(!store_ctx, ret = -1, cleanup);
 
     /* init store context */
     ret = X509_STORE_CTX_init(store_ctx, crl_store, NULL, NULL);
@@ -1126,10 +1107,7 @@
     data = (struct nc_curl_data *)userdata;
 
     data->data = nc_realloc(data->data, data->size + size);
-    if (!data->data) {
-        ERRMEM;
-        return 0;
-    }
+    NC_CHECK_ERRMEM_RET(!data->data, 0);
 
     memcpy(&data->data[data->size], ptr, size);
     data->size += size;
@@ -1361,10 +1339,7 @@
     if (!opts->crl_store) {
         /* first call on this endpoint */
         opts->crl_store = X509_STORE_new();
-        if (!opts->crl_store) {
-            ERRMEM;
-            goto fail;
-        }
+        NC_CHECK_ERRMEM_GOTO(!opts->crl_store,; , fail);
     }
 
     if (opts->crl_path) {