Bug 48651

Summary: [TRIVIAl]'xfs_uuid_table' allocated in xfs_uuid_mount() is never freed
Product: File System Reporter: Eugene A. Shatokhin (eugene.shatokhin)
Component: XFSAssignee: XFS Guru (xfs-masters)
Status: RESOLVED CODE_FIX    
Severity: normal CC: alan, sandeen, sandeen, szg00000, xerofoify
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.6 Subsystem:
Regression: No Bisected commit-id:

Description Eugene A. Shatokhin 2012-10-09 12:41:13 UTC
The memory for 'xfs_uuid_table' is allocated in xfs_uuid_mount() but is never freed (see xfs_mount.c).

Not sure where exactly it is appropriate to call kmem_free() for it. Perhaps, - in the exit-function of XFS kernel module or when the table becomes empty?

Found this problem with the memory leak detector from KEDR Framework when running xfstests suite.
Comment 1 xerofoify 2014-04-18 19:25:20 UTC
Firstly ,I do not know the codebase of XFS that well, however it will depend on when the table is freed if when the volumes are unmounted in that case I would free after the table is empty , but I would recommend doing in the module_exit() function for xfs due to the certainity it will sucess in not causing further issues as you then have certainty the filesystem module is no longer in use.
Comment 2 Eric Sandeen 2014-05-20 04:01:20 UTC
Freeing it when the module is unloaded should be sufficient.

In normal use, unmounting a filesystem creates a hole in the table, which the next mount can fill.

If you mount a lot of unique UUID filesystems without unmounting any in between, the table will grow accordingly, and unmounting won't shrink it - i.e. the table only grows as the number of concurrently mounted filesystem grows, but that doesn't seem like a particularly critical problem to fix.
Comment 3 xerofoify 2014-06-15 02:37:11 UTC
Can you tell me where the module_exit is so I can use kmee_free to free it.
Please tell me the file and the values send to xfs_uuid_table in order to correctly free it.
Cheers Nick
Comment 4 Eric Sandeen 2016-09-22 16:14:42 UTC
Fixed in v4.4:

commit af3b63822e73b66f3ca9927b46df8b873ab8c6ec
Author: Darrick J. Wong <darrick.wong@oracle.com>
Date:   Tue Nov 3 13:06:34 2015 +1100

    xfs: don't leak uuid table on rmmod
    
    Don't leak the UUID table when the module is unloaded.
    (Found with kmemleak.)
    
    Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
    Reviewed-by: Dave Chinner <dchinner@redhat.com>
    Signed-off-by: Dave Chinner <david@fromorbit.com>