[patch 1/5] iptables: fix invalid free

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In iptablesContextNew(), make sure we don't try and free an invalid
pointer if one of the iptRulesNew() fails.

Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx>

Index: libvirt/qemud/iptables.c
===================================================================
--- libvirt.orig/qemud/iptables.c
+++ libvirt/qemud/iptables.c
@@ -496,7 +496,7 @@ iptablesContextNew(void)
 {
     iptablesContext *ctx;
 
-    if (!(ctx = (iptablesContext *) malloc(sizeof (iptablesContext))))
+    if (!(ctx = (iptablesContext *) calloc(1, sizeof (iptablesContext))))
         return NULL;
 
     if (!(ctx->input_filter = iptRulesNew("filter", IPTABLES_PREFIX "INPUT")))
@@ -518,9 +518,12 @@ iptablesContextNew(void)
 void
 iptablesContextFree(iptablesContext *ctx)
 {
-    iptRulesFree(ctx->input_filter);
-    iptRulesFree(ctx->forward_filter);
-    iptRulesFree(ctx->nat_postrouting);
+    if (ctx->input_filter)
+        iptRulesFree(ctx->input_filter);
+    if (ctx->forward_filter)
+        iptRulesFree(ctx->forward_filter);
+    if (ctx->nat_postrouting)
+        iptRulesFree(ctx->nat_postrouting);
     free(ctx);
 }
 

-- 


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]