Instead of allocating new memory, move the string to the new array.
Free the string if it matched. Unconditionally set the old array
entry to NULL.
---
src/service.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/src/service.c b/src/service.c
index f3f384f..a3c2a81 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1172,12 +1172,13 @@ int __connman_service_nameserver_remove(struct
connman_service *service,
return -ENOMEM;
for (i = 0, j = 0; i < len; i++) {
- if (g_strcmp0(nameservers[i], nameserver) != 0) {
- servers[j] = g_strdup(nameservers[i]);
- if (!servers[j])
- return -ENOMEM;
+ if (g_strcmp0(nameservers[i], nameserver)) {
+ servers[j] = nameservers[i];
j++;
- }
+ } else
+ g_free(nameservers[i]);
+
+ nameservers[i] = NULL;
}
servers[len - 1] = NULL;
--
2.1.4
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman