yin parser CHANGE support substatements' extensions of the extension statement
diff --git a/src/parser_yin.c b/src/parser_yin.c
index 6d50562..c954312 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -1633,6 +1633,7 @@
     const char *value;
     struct lyxml_elem *child, *node, *next, *next2;
     int c_ext = 0, rc;
+    void *reallocated;
 
     GETVAL(value, yin, "name");
 
@@ -1653,6 +1654,9 @@
             /* argument */
             GETVAL(value, node, "name");
             ext->argument = lydict_insert(module->ctx, value, strlen(value));
+            if (read_yin_subnode_ext(module, ext, LYEXT_PAR_EXT, node, LYEXT_SUBSTMT_ARGUMENT, 0, unres)) {
+                goto error;
+            }
 
             /* yin-element */
             LY_TREE_FOR_SAFE(node->child, next2, child) {
@@ -1661,6 +1665,10 @@
                     if (ly_strequal(value, "true", 0)) {
                         ext->flags |= LYS_YINELEM;
                     }
+
+                    if (read_yin_subnode_ext(module, ext, LYEXT_PAR_EXT, child, LYEXT_SUBSTMT_YINELEM, 0, unres)) {
+                        goto error;
+                    }
                 } else if (child->ns) {
                     /* unexpected YANG statement */
                     LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name);
@@ -1677,11 +1685,18 @@
     }
 
     if (c_ext) {
-        ext->ext = calloc(c_ext, sizeof *ext->ext);
-        if (!ext->ext) {
+        /* some extensions may be already present from the substatements */
+        reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext);
+        if (!reallocated) {
             LOGMEM;
             goto error;
         }
+        ext->ext = reallocated;
+
+        /* init memory */
+        memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext);
+
+        /* process the extension instances of the extension itself */
         LY_TREE_FOR_SAFE(yin->child, next, node) {
             rc = lyp_yin_fill_ext(ext, LYEXT_PAR_EXT, 0, 0, module, node, &ext->ext, ext->ext_size, unres);
             ext->ext_size++;