make the uci_ptr struct reusable after a call to uci_delete()
[project/uci.git] / list.c
diff --git a/list.c b/list.c
index b4f4da8..9486ffb 100644 (file)
--- a/list.c
+++ b/list.c
@@ -527,6 +527,9 @@ int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
                free(e->name);
        e->name = n;
 
+       if (e->type == UCI_TYPE_SECTION)
+               uci_to_section(e)->anonymous = false;
+
        return 0;
 }
 
@@ -564,6 +567,12 @@ int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
                uci_add_history(ctx, &p->history, UCI_CMD_REMOVE, ptr->section, ptr->option, NULL);
 
        uci_free_any(&e);
+
+       if (ptr->option)
+               ptr->o = NULL;
+       else if (ptr->section)
+               ptr->s = NULL;
+
        return 0;
 }