compile schema BUGFIX check duplicates for augmented/deviated by arrays
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index 4417027..4767760 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -4373,7 +4373,7 @@
 LY_ERR
 lys_compile_augment(struct lysc_ctx *ctx, struct lysp_augment *aug_p, const struct lysc_node *parent)
 {
-    LY_ERR ret = LY_SUCCESS;
+    LY_ERR ret = LY_SUCCESS, rc;
     struct lysp_node *node_p, *case_node_p;
     struct lysc_node *target; /* target target of the augment */
     struct lysc_node *node;
@@ -4381,7 +4381,7 @@
     struct lys_module **aug_mod;
     int allow_mandatory = 0;
     uint16_t flags = 0;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u, v;
     int opt_prev = ctx->options;
 
     lysc_update_path(ctx, NULL, "{augment}");
@@ -4512,9 +4512,18 @@
         }
     }
 
-    /* add this module into the target module augmented_by */
-    LY_ARRAY_NEW_GOTO(ctx->ctx, target->module->compiled->augmented_by, aug_mod, ret, error);
-    *aug_mod = ctx->mod;
+    /* add this module into the target module augmented_by, if not there already */
+    rc = LY_SUCCESS;
+    LY_ARRAY_FOR(target->module->compiled->augmented_by, v) {
+        if (target->module->compiled->augmented_by[v] == ctx->mod) {
+            rc = LY_EEXIST;
+            break;
+        }
+    }
+    if (!rc) {
+        LY_ARRAY_NEW_GOTO(ctx->ctx, target->module->compiled->augmented_by, aug_mod, ret, error);
+        *aug_mod = ctx->mod;
+    }
 
     lysc_update_path(ctx, NULL, NULL);
     lysc_update_path(ctx, NULL, NULL);
@@ -6455,9 +6464,18 @@
             goto cleanup;
         }
 
-        /* add this module into the target module deviated_by */
-        LY_ARRAY_NEW_GOTO(ctx->ctx, devs[u]->target->module->compiled->deviated_by, dev_mod, ret, cleanup);
-        *dev_mod = mod_p->mod;
+        /* add this module into the target module deviated_by, if not there already */
+        rc = LY_SUCCESS;
+        LY_ARRAY_FOR(devs[u]->target->module->compiled->deviated_by, v) {
+            if (devs[u]->target->module->compiled->deviated_by[v] == mod_p->mod) {
+                rc = LY_EEXIST;
+                break;
+            }
+        }
+        if (!rc) {
+            LY_ARRAY_NEW_GOTO(ctx->ctx, devs[u]->target->module->compiled->deviated_by, dev_mod, ret, cleanup);
+            *dev_mod = mod_p->mod;
+        }
 
         lysc_update_path(ctx, NULL, NULL);
     }