afb-api-v3: Simplify the code
[src/app-framework-binder.git] / src / afb-api-v3.c
index 1bda6b0..7f63b6e 100644 (file)
@@ -239,6 +239,9 @@ void afb_api_v3_unref(struct afb_api_v3 *api)
 {
        if (api && !__atomic_sub_fetch(&api->refcount, 1, __ATOMIC_RELAXED)) {
                afb_export_destroy(api->export);
+               while (api->count)
+                       free(api->verbs[--api->count]);
+               free(api->verbs);
                free(api);
        }
 }
@@ -322,19 +325,16 @@ int afb_api_v3_del_verb(
                const char *verb,
                void **vcbdata)
 {
-       struct afb_verb_v3 **v, **e, *i;
+       struct afb_verb_v3 *v;
+       int i;
 
-       v = api->verbs;
-       e = &v[api->count];
-       while (v != e) {
-               i = *v++;
-               if (!strcasecmp(i->verb, verb)) {
-                       api->count--;
+       for (i = 0 ; i < api->count ; i++) {
+               v = api->verbs[i];
+               if (!strcasecmp(verb, v->verb)) {
+                       api->verbs[i] = api->verbs[--api->count];
                        if (vcbdata)
-                               *vcbdata = i->vcbdata;
-                       if (v != e)
-                               *--v = *--e;
-                       free(i);
+                               *vcbdata = v->vcbdata;
+                       free(v);
                        return 0;
                }
        }