stp: Fix memory leak.
authorBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 22:03:36 +0000 (14:03 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 2 Feb 2010 23:21:09 +0000 (15:21 -0800)
Found with valgrind.

lib/stp.c

index cf1b2f9..6fad3a0 100644 (file)
--- a/lib/stp.c
+++ b/lib/stp.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -256,7 +256,10 @@ stp_create(const char *name, stp_identifier bridge_id,
 void
 stp_destroy(struct stp *stp)
 {
-    free(stp);
+    if (stp) {
+        free(stp->name);
+        free(stp);
+    }
 }
 
 /* Runs 'stp' given that 'ms' milliseconds have passed. */