[LEDE-DEV] [PATCH] uci: decrement package's section counter when free'ing sections

Reiner Herrmann reiner at reiner-h.de
Tue Sep 13 15:21:13 PDT 2016


On Tue, Sep 13, 2016 at 10:52:43PM +0200, Felix Fietkau wrote:
> On 2016-09-13 16:25, Reiner Herrmann wrote:
> > The counter is incremented during section allocation, but never
> > decremented.
> NACK. n_section is used for hashing only, decrementing it here probably
> makes collisions for anonymous sections more likely.

I was encountering a strange behaviour related to adding/deleting
sections, like in the example below.
There I'm adding two sections, deleting one, commiting, deleting the
other, and commiting again.
I would expect that afterwards the package is empty and there is no
diff in the save dir.
But it is the case:

$ uci -c /tmp/uci -X show
foo.cfg0260ba=bar
$ cat /tmp/.uci/foo
-foo.cfg0460ba

In a slightly more complex example the patch (decrementing the counter)
seemed to help. Though with the minimal example from below, the issue
also still exists...


#include <uci.h>
#include <string.h>

int main()
{
	struct uci_ptr ptr;
	struct uci_context *ctx = uci_alloc_context();
	struct uci_section *section;
	
	uci_set_confdir(ctx, "/tmp/uci");
	uci_lookup_ptr(ctx, &ptr, "foo", 0);

	/* Add two sections */
	uci_add_section(ctx, ptr.p, "bar", &section);
	uci_add_section(ctx, ptr.p, "bar", &section);

	/* Delete one section */
	uci_lookup_ptr(ctx, &ptr, strdup("foo. at bar[0]"), 1);
	uci_delete(ctx, &ptr);
	uci_save(ctx, ptr.p);
	uci_commit(ctx, &ptr.p, 1);

	/* Delete other section */
	uci_lookup_ptr(ctx, &ptr, strdup("foo. at bar[0]"), 1);
	uci_delete(ctx, &ptr);
	uci_save(ctx, ptr.p);
	uci_commit(ctx, &ptr.p, 1);


	return 0;
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20160914/74b3bc59/attachment.sig>


More information about the Lede-dev mailing list