aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2008-08-13 02:04:05 -0400
committerLachlan McIlroy <lachlan@redback.melbourne.sgi.com>2008-08-13 02:04:05 -0400
commita738159df2b97398f960978272944cbdd8f726ef (patch)
tree20959d5f1d941dd7c755bf9bc8141f20f97249dd /fs/xfs
parent5e9da7b7a1edfc75a839b0269935393fa347f38b (diff)
[XFS] don't leak m_fsname/m_rtname/m_logname
Add a helper to free the m_fsname/m_rtname/m_logname allocations and use it properly for all mount failure cases. Also switch the allocations for these to kstrdup while we're at it. SGI-PV: 981498 SGI-Modid: xfs-linux-melb:xfs-kern:31728a Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Niv Sardi <xaiki@sgi.com> Signed-off-by: David Chinner <david@fromorbit.com> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c51
-rw-r--r--fs/xfs/xfs_mount.c7
2 files changed, 41 insertions, 17 deletions
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index c9ec44a02e21..27758409fc85 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -1201,6 +1201,15 @@ xfssyncd(
1201} 1201}
1202 1202
1203STATIC void 1203STATIC void
1204xfs_free_fsname(
1205 struct xfs_mount *mp)
1206{
1207 kfree(mp->m_fsname);
1208 kfree(mp->m_rtname);
1209 kfree(mp->m_logname);
1210}
1211
1212STATIC void
1204xfs_fs_put_super( 1213xfs_fs_put_super(
1205 struct super_block *sb) 1214 struct super_block *sb)
1206{ 1215{
@@ -1261,6 +1270,7 @@ xfs_fs_put_super(
1261 xfs_close_devices(mp); 1270 xfs_close_devices(mp);
1262 xfs_qmops_put(mp); 1271 xfs_qmops_put(mp);
1263 xfs_dmops_put(mp); 1272 xfs_dmops_put(mp);
1273 xfs_free_fsname(mp);
1264 kfree(mp); 1274 kfree(mp);
1265} 1275}
1266 1276
@@ -1517,6 +1527,8 @@ xfs_start_flags(
1517 struct xfs_mount_args *ap, 1527 struct xfs_mount_args *ap,
1518 struct xfs_mount *mp) 1528 struct xfs_mount *mp)
1519{ 1529{
1530 int error;
1531
1520 /* Values are in BBs */ 1532 /* Values are in BBs */
1521 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { 1533 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1522 /* 1534 /*
@@ -1549,17 +1561,27 @@ xfs_start_flags(
1549 ap->logbufsize); 1561 ap->logbufsize);
1550 return XFS_ERROR(EINVAL); 1562 return XFS_ERROR(EINVAL);
1551 } 1563 }
1564
1565 error = ENOMEM;
1566
1552 mp->m_logbsize = ap->logbufsize; 1567 mp->m_logbsize = ap->logbufsize;
1553 mp->m_fsname_len = strlen(ap->fsname) + 1; 1568 mp->m_fsname_len = strlen(ap->fsname) + 1;
1554 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP); 1569
1555 strcpy(mp->m_fsname, ap->fsname); 1570 mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
1571 if (!mp->m_fsname)
1572 goto out;
1573
1556 if (ap->rtname[0]) { 1574 if (ap->rtname[0]) {
1557 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP); 1575 mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
1558 strcpy(mp->m_rtname, ap->rtname); 1576 if (!mp->m_rtname)
1577 goto out_free_fsname;
1578
1559 } 1579 }
1580
1560 if (ap->logname[0]) { 1581 if (ap->logname[0]) {
1561 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP); 1582 mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
1562 strcpy(mp->m_logname, ap->logname); 1583 if (!mp->m_logname)
1584 goto out_free_rtname;
1563 } 1585 }
1564 1586
1565 if (ap->flags & XFSMNT_WSYNC) 1587 if (ap->flags & XFSMNT_WSYNC)
@@ -1632,6 +1654,14 @@ xfs_start_flags(
1632 if (ap->flags & XFSMNT_DMAPI) 1654 if (ap->flags & XFSMNT_DMAPI)
1633 mp->m_flags |= XFS_MOUNT_DMAPI; 1655 mp->m_flags |= XFS_MOUNT_DMAPI;
1634 return 0; 1656 return 0;
1657
1658
1659 out_free_rtname:
1660 kfree(mp->m_rtname);
1661 out_free_fsname:
1662 kfree(mp->m_fsname);
1663 out:
1664 return error;
1635} 1665}
1636 1666
1637/* 1667/*
@@ -1792,10 +1822,10 @@ xfs_fs_fill_super(
1792 */ 1822 */
1793 error = xfs_start_flags(args, mp); 1823 error = xfs_start_flags(args, mp);
1794 if (error) 1824 if (error)
1795 goto out_destroy_counters; 1825 goto out_free_fsname;
1796 error = xfs_readsb(mp, flags); 1826 error = xfs_readsb(mp, flags);
1797 if (error) 1827 if (error)
1798 goto out_destroy_counters; 1828 goto out_free_fsname;
1799 error = xfs_finish_flags(args, mp); 1829 error = xfs_finish_flags(args, mp);
1800 if (error) 1830 if (error)
1801 goto out_free_sb; 1831 goto out_free_sb;
@@ -1857,7 +1887,8 @@ xfs_fs_fill_super(
1857 xfs_filestream_unmount(mp); 1887 xfs_filestream_unmount(mp);
1858 out_free_sb: 1888 out_free_sb:
1859 xfs_freesb(mp); 1889 xfs_freesb(mp);
1860 out_destroy_counters: 1890 out_free_fsname:
1891 xfs_free_fsname(mp);
1861 xfs_icsb_destroy_counters(mp); 1892 xfs_icsb_destroy_counters(mp);
1862 xfs_close_devices(mp); 1893 xfs_close_devices(mp);
1863 out_put_qmops: 1894 out_put_qmops:
@@ -1893,7 +1924,7 @@ xfs_fs_fill_super(
1893 IRELE(mp->m_rootip); 1924 IRELE(mp->m_rootip);
1894 1925
1895 xfs_unmountfs(mp); 1926 xfs_unmountfs(mp);
1896 goto out_destroy_counters; 1927 goto out_free_fsname;
1897} 1928}
1898 1929
1899STATIC int 1930STATIC int
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 6c5d1325e7f6..31699b19bb3c 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -146,13 +146,6 @@ xfs_mount_free(
146 mutex_destroy(&mp->m_growlock); 146 mutex_destroy(&mp->m_growlock);
147 if (mp->m_quotainfo) 147 if (mp->m_quotainfo)
148 XFS_QM_DONE(mp); 148 XFS_QM_DONE(mp);
149
150 if (mp->m_fsname != NULL)
151 kmem_free(mp->m_fsname);
152 if (mp->m_rtname != NULL)
153 kmem_free(mp->m_rtname);
154 if (mp->m_logname != NULL)
155 kmem_free(mp->m_logname);
156} 149}
157 150
158/* 151/*