ovs-thread: Fix memory leak in thread exit.
authorBen Pfaff <blp@ovn.org>
Tue, 10 Nov 2015 21:13:28 +0000 (13:13 -0800)
committerBen Pfaff <blp@ovn.org>
Tue, 10 Nov 2015 22:11:28 +0000 (14:11 -0800)
'n' is the number of keys, which are grouped into blocks of L2_SIZE
indexes.  Even if only one key in a block is allocated, the whole block has
a pointer to it that must be freed.  Thus, we need to round up instead of
down.

Reported-at: https://github.com/openvswitch/ovs/pull/87
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
lib/ovs-thread.c

index 88b92d1..2f6bc58 100644 (file)
@@ -665,7 +665,7 @@ ovsthread_key_destruct__(void *slots_)
     n = n_keys;
     ovs_mutex_unlock(&key_mutex);
 
-    for (i = 0; i < n / L2_SIZE; i++) {
+    for (i = 0; i < DIV_ROUND_UP(n, L2_SIZE); i++) {
         free(slots->p1[i]);
     }
     free(slots);