]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
tevent: Remove single-use ev_str_list_[length|add]
authorVolker Lendecke <vl@samba.org>
Mon, 3 May 2021 20:03:47 +0000 (22:03 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 4 Jun 2021 16:47:34 +0000 (16:47 +0000)
This also adds proper error checks, the previous code could (very
theoretically) have leaked memory if an intermediate _add had failed.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tevent/tevent.c
lib/tevent/tevent_util.c
lib/tevent/tevent_util.h

index dbec1821e41c7297e1e8bd1c85126e1fd59d8112..a94bb440b9ba501debcfcf0f343fcf1b8d01a84f 100644 (file)
@@ -166,14 +166,28 @@ const char **tevent_backend_list(TALLOC_CTX *mem_ctx)
 {
        const char **list = NULL;
        struct tevent_ops_list *e;
+       size_t idx = 0;
 
        tevent_backend_init();
 
        for (e=tevent_backends;e;e=e->next) {
-               list = ev_str_list_add(list, e->name);
+               idx += 1;
        }
 
-       talloc_steal(mem_ctx, list);
+       list = talloc_zero_array(mem_ctx, const char *, idx+1);
+       if (list == NULL) {
+               return NULL;
+       }
+
+       idx = 0;
+       for (e=tevent_backends;e;e=e->next) {
+               list[idx] = talloc_strdup(list, e->name);
+               if (list[idx] == NULL) {
+                       TALLOC_FREE(list);
+                       return NULL;
+               }
+               idx += 1;
+       }
 
        return list;
 }
index 16af8f3b908d8c0502a18403ac70a0b476df1419..7519e118ab929d4997e06c47a8232047bd7c0f24 100644 (file)
 #include "tevent_util.h"
 #include <fcntl.h>
 
-/**
-  return the number of elements in a string list
-*/
-size_t ev_str_list_length(const char **list)
-{
-       size_t ret;
-       for (ret=0;list && list[ret];ret++) /* noop */ ;
-       return ret;
-}
-
-/**
-  add an entry to a string list
-*/
-const char **ev_str_list_add(const char **list, const char *s)
-{
-       size_t len = ev_str_list_length(list);
-       const char **ret;
-
-       ret = talloc_realloc(NULL, list, const char *, len+2);
-       if (ret == NULL) return NULL;
-
-       ret[len] = talloc_strdup(ret, s);
-       if (ret[len] == NULL) return NULL;
-
-       ret[len+1] = NULL;
-
-       return ret;
-}
-
-
 /**
  Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available,
  else
index eef4a00f98b414f7ed4ee972484f219cc0acab5a..128c231e25cfac3d7580ad72eb708e5cc0caeefb 100644 (file)
@@ -173,9 +173,7 @@ do { \
 
 #endif /* _DLINKLIST_H */
 
-const char **ev_str_list_add(const char **list, const char *s);
 int ev_set_blocking(int fd, bool set);
-size_t ev_str_list_length(const char **list);
 bool ev_set_close_on_exec(int fd);
 
 /* Defined here so we can build against older talloc versions that don't