- UCI_INTERNAL(uci_save, ctx, p);
- name = uci_strdup(ctx, p->e.name);
+ UCI_INTERNAL(uci_save, ctx, ptr->p);
+
+ /* NB: need to clone package, section and option names,
+ * as they may get freed on uci_free_package() */
+ package = uci_strdup(ctx, ptr->p->e.name);
+ if (ptr->section)
+ section = uci_strdup(ctx, ptr->section);
+ if (ptr->option)
+ option = uci_strdup(ctx, ptr->option);