r11794: - fixed a valgrind error in libnet, caused by using a stack variable
authorAndrew Tridgell <tridge@samba.org>
Fri, 18 Nov 2005 23:27:58 +0000 (23:27 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:46:28 +0000 (13:46 -0500)
  after the function has returned (the *address variable was assigned
  into the state).

- changed libnet to use event_context_find() instead of
  event_context_init(), so it works as a child of existing code that
  uses a event context
(This used to be commit 47ceb2d3558304b4c4fb00582fb25a885cea2ef5)

source4/libnet/libnet.c
source4/libnet/libnet_lookup.c
source4/libnet/libnet_rpc.c

index 604a2aaca45deb8a8d10648a4716e65d998e3a62..b7b18b7417e78658326a8f9bff8a0c081ee29339 100644 (file)
@@ -38,7 +38,7 @@ struct libnet_context *libnet_context_init(struct event_context *ev)
 
        /* events */
        if (ev == NULL) {
-               ev = event_context_init(ctx);
+               ev = event_context_find(ctx);
                if (ev == NULL) {
                        talloc_free(ctx);
                        return NULL;
index 7cc05324d6b5a5ac65948e645313b9ced45947a2..67c102a3e2e0309c8a5933b181be4f43a906da1f 100644 (file)
@@ -34,7 +34,6 @@
 struct lookup_state {
        struct composite_context *resolve_ctx;
        struct nbt_name hostname;
-       const char **address;
 };
 
 
@@ -50,7 +49,6 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
        struct composite_context *c;
        struct lookup_state *s;
        const char** methods;
-       const char* address = talloc_array(ctx, const char, 16);
 
        if (!io) return NULL;
 
@@ -62,14 +60,13 @@ struct composite_context *libnet_Lookup_send(struct libnet_context *ctx,
        if (s == NULL) goto failed;
        
        /* prepare event context */
-       c->event_ctx = event_context_init(c);
+       c->event_ctx = event_context_find(c);
        if (c->event_ctx == NULL) goto failed;
 
        /* parameters */
        s->hostname.name   = talloc_strdup(s, io->in.hostname);
        s->hostname.type   = io->in.type;
        s->hostname.scope  = NULL;
-       s->address         = &address;
 
        /* name resolution methods */
        if (io->in.methods) {
@@ -106,12 +103,14 @@ NTSTATUS libnet_Lookup_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
 {
        NTSTATUS status;
        struct lookup_state *s;
+       const char *address;
 
        s = talloc_get_type(c->private_data, struct lookup_state);
 
-       status = resolve_name_recv(s->resolve_ctx, mem_ctx, s->address);
+       status = resolve_name_recv(s->resolve_ctx, mem_ctx, &address);
        if (NT_STATUS_IS_OK(status)) {
-               io->out.address = s->address;
+               io->out.address = str_list_make(mem_ctx, address, NULL);
+               NT_STATUS_HAVE_NO_MEMORY(io->out.address);
        }
 
        return status;
index 7b07cedeacc83219ff1a59eff65aa9b36259a4ab..9917b172557295b09a9cb6eeefe0e6c1082ddfc1 100644 (file)
@@ -77,11 +77,10 @@ static NTSTATUS libnet_RpcConnectPdc(struct libnet_context *ctx, TALLOC_CTX *mem
        NTSTATUS status;
        struct libnet_RpcConnect r2;
        struct libnet_Lookup f;
-       const char *address = talloc_array(ctx, const char, 16);
 
        f.in.hostname  = r->in.domain_name;
        f.in.methods   = NULL;
-       f.out.address  = &address;
+       f.out.address  = NULL;
 
        status = libnet_LookupPdc(ctx, mem_ctx, &f);
        if (!NT_STATUS_IS_OK(status)) {
@@ -91,7 +90,7 @@ static NTSTATUS libnet_RpcConnectPdc(struct libnet_context *ctx, TALLOC_CTX *mem
        }
 
        r2.level                    = LIBNET_RPC_CONNECT_SERVER;
-       r2.in.domain_name           = talloc_strdup(mem_ctx, *f.out.address);
+       r2.in.domain_name           = talloc_strdup(mem_ctx, f.out.address[0]);
        r2.in.dcerpc_iface_name     = r->in.dcerpc_iface_name;
        r2.in.dcerpc_iface_uuid     = r->in.dcerpc_iface_uuid;
        r2.in.dcerpc_iface_version  = r->in.dcerpc_iface_version;