Memory leak on UBI volume truncating

Marek Skuczynski mareksk7 at gmail.com
Wed Jan 13 09:28:58 EST 2010


Hello,
  I have prepare a simple volume update stress test (see test code below).
  This test has been run for kernel 2.6.23 with some updates from 2.6.28,
  and always after a few minutes the OOM killer was launched.

  What i found it that each an UBI volume truncate operation with
ubiupdatevol tool
  causes memory leak. I think this happens because:

  - ubi_start_update()  param "bytes" is equal 0

  - vol->updating flag is re-set to 0

  - vol->upd_buf is allocated regardless of vol->updating flag,
     but not released on device close by vol_cdev_release()

  I never run the test on a newer kernel version, so I cannot confirm
that this problem still exists.

  Please confirm, whether my findings are correct or not, thanks.

Regards,
  Marek


int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
    long long bytes)
   /* ... */
   vol->updating = 1;

   if (bytes == 0) {
        /* ... */
        vol->updating = 0;
   }

   vol->upd_buf = vmalloc(ubi->leb_size);
   /* ... */
}

static int vol_cdev_release(struct inode *inode, struct file *file)
{
  /* ... */
   if (vol->updating) {
      /* ... */
      vol->updating = 0;
      vfree(vol->upd_buf);
   }
   /* ... */
}

[--- TEST BODY ----]
while [ true ]
do
   echo "Truncating #1"
   /tmp/ubiupdatevol /dev/ubi0_3 -t
   echo "Writing #1"
   cat /dev/zero  | /tmp/ubiupdatevol /dev/ubi0_3 -s 4206 -
   echo "Truncating #2"
   /tmp/ubiupdatevol /dev/ubi0_3 -t
   echo "Writing #2"
   cat /dev/urandom  | /tmp/ubiupdatevol /dev/ubi0_3 -s 4206 -
done



More information about the linux-mtd mailing list