1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

tevent: Remove single-use ev_str_list_[length|add]

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>
This commit is contained in:
Volker Lendecke 2021-05-03 22:03:47 +02:00 committed by Jeremy Allison
parent b619195689
commit 8ee391bbd0
3 changed files with 16 additions and 34 deletions

View 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;
}

View File

@ -29,36 +29,6 @@
#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

View 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