Ticket #188: mountlist-free_mount_list.patch

File mountlist-free_mount_list.patch, 1005 bytes (added by andrew_b, 15 years ago)

Fix of memory leak in init_my_statsf()

  • src/mountlist.c

    diff --git a/src/mountlist.c b/src/mountlist.c
    index bd9e8d9..1bef645 100644
    a b static int get_fs_usage (char *path, struct fs_usage *fsp); 
    148148 
    149149static struct mount_entry *mount_list = NULL; 
    150150 
     151static void free_mount_entry (struct mount_entry *me) 
     152{ 
     153    if (!me) 
     154        return; 
     155    if (me->me_devname) 
     156        free (me->me_devname); 
     157    if (me->me_mountdir) 
     158        free (me->me_mountdir); 
     159    if (me->me_type) 
     160        free (me->me_type); 
     161    free (me); 
     162} 
     163 
    151164#ifdef MOUNTED_GETMNTENT1       /* 4.3BSD, SunOS, HP-UX, Dynix, Irix.  */ 
    152165/* Return the value of the hexadecimal number represented by CP. 
    153166   No prefix (like '0x') or suffix (like 'h') is expected to be 
    void 
    675688init_my_statfs (void) 
    676689{ 
    677690#ifdef HAVE_INFOMOUNT_LIST 
     691    while (mount_list) { 
     692        struct mount_entry *next = mount_list->me_next; 
     693        free_mount_entry (mount_list); 
     694        mount_list = next; 
     695    } 
     696 
    678697    mount_list = read_filesystem_list (1, 1); 
    679698#endif /* HAVE_INFOMOUNT_LIST */ 
    680699}