about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-06-30 11:52:50 -0700
committerEric Wong <normalperson@yhbt.net>2011-06-30 11:52:50 -0700
commitb99e6cbd055fbf8664ee510c2e60854d10c69d51 (patch)
tree53218c51ecee99f378698a00ffcc20d88b6dd3df
parent8301a96e8f11f668a717afbdf95f3695cdc9ca3b (diff)
downloadlibnodelay-b99e6cbd055fbf8664ee510c2e60854d10c69d51.tar.gz
do not rely on implementation-specific behavior for allocation v1.0.1
C compilers are free to release stack-allocated memory once it
exits the scope of any block (even though most do not).

Thanks to Leonid Evdokimov for pointing this out.
-rw-r--r--nodelay.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/nodelay.c b/nodelay.c
index d24e1bf..265b0d6 100644
--- a/nodelay.c
+++ b/nodelay.c
@@ -72,11 +72,13 @@ int socket(int domain, int type, int protocol)
 int setsockopt(int sockfd, int level, int optname,
                const void *poptval, socklen_t optlen)
 {
+        int optval;
+
         if (unlikely(!real_socket))
                 nodelay_init();
 
         if (level == IPPROTO_TCP && optname == TCP_NODELAY) {
-                int optval = nodelay_value;
+                optval = nodelay_value;
 
                 poptval = &optval;
                 optlen = sizeof(optval);