]> git.ozlabs.org Git - ccan-lca-2011.git/commitdiff
lca2011: valgrind catches an error for us.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 04:42:21 +0000 (15:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 21 Jan 2011 04:42:21 +0000 (15:12 +1030)
When we moved the clients[] array into oserver, we didn't initialize it.
Before, it was a static, so implicitly set to NULL.

ccan/oserver/_info
ccan/oserver/oserver.c

index 5dfc5f88fb27a001e1e9b68fb807cbbf9ff669e0..5a69855d2bb06f2c5a89442335ebd9eb9c915b98 100644 (file)
@@ -8,10 +8,6 @@
  *
  * License: GPL
  *
- * Ccanlint:
- *     // hack to make valgrind show the error.  FIXME!
- *     tests_pass_valgrind  --child-silent-after-fork=no
- *
  * Example:
  *     #include <sys/types.h>
  *     #include <sys/socket.h>
index 3256369d6d189eab13cc7790bc02e32ac1528103..076ba70b4c15930eeb7cfde0ffb6e2eed1a38a57 100644 (file)
@@ -178,6 +178,12 @@ static void add_client(struct tevent_context *ev,
                tevent_fd_set_flags(oserver->fde, 0);
 }
 
+static void clear_clients(struct oserver *oserver)
+{
+       memset(oserver->clients, 0,
+              ARRAY_SIZE(oserver->clients) * sizeof(oserver->clients[0]));
+}
+
 static int destroy_oserver(struct oserver *oserver)
 {
        close(oserver->fd);
@@ -194,12 +200,13 @@ struct oserver *oserver_setup(struct tevent_context *ev, unsigned short port)
        } u;
 
        oserver = talloc(ev, struct oserver);
-
+       clear_clients(oserver);
        oserver->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (oserver->fd < 0) {
                talloc_free(oserver);
                return NULL;
        }
+       
        talloc_set_destructor(oserver, destroy_oserver);
 
        if (setsockopt(oserver->fd, SOL_SOCKET, SO_REUSEADDR,