My first Coverity mdadm fix

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

 



Trying to fix a resource leak in Assemble.c

A superblock is copied into variable tst using dup_super, which does an xcalloc.

The section of code in question returns with an error without freeing tst.

Further down, tst is cleared with a call to free_super, which does a load of extra work like closing files etc.

So my question is basically, which is the correct free function to call? I think we're just throwing the duplicate away, in which case xfree is the correct function. But elsewhere it is using free_super - which if I call wrongly will mess up code accessing the original superblock that was copied.

If you can confirm my suspicion either way, I'll submit a proper patch ...

Cheers,
Wol
diff --git a/Assemble.c b/Assemble.c
index e83d550..610e869 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -281,7 +281,12 @@ static int select_devices(struct mddev_dev *devlist,
 				st->ss->free_super(st);
 			dev_policy_free(pol);
 			domain_free(domains);
-			return -1;
+            
+            // Which of these is correct ??
+            xfree(tst)
+            tst->ss->free_super(tst);
+
+            return -1;
 		}
 
 		if (found_container) {

[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux