]> git.ipfire.org Git - thirdparty/openwrt.git/commit
mtd: fix buffer leak and fd leak in mtd_dump() 23706/head
authorAnna Kiri <bredcorn@gmail.com>
Mon, 8 Jun 2026 09:07:05 +0000 (11:07 +0200)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Mon, 8 Jun 2026 14:18:23 +0000 (16:18 +0200)
commita5107ad58c6162a70a56ada1822c3c3e6ba09a12
tree7f62f4bfde7006770a7fa3052202af02f592488d
parent2818ac5ccd0cc7c44176010691929b843b7cb566
mtd: fix buffer leak and fd leak in mtd_dump()

Two leaks in mtd_dump():

- The buffer allocated with malloc(erasesize) is never freed before
  returning, leaking erasesize bytes on every call.
- The pre-existing malloc-NULL early return path also leaked the just-
  opened fd by returning directly instead of going through cleanup.

Initialize buf to NULL, route the malloc-NULL case through the
existing 'out:' label, and add free(buf) on the cleanup path so both
fd and buf are released consistently on every exit.

Signed-off-by: Anna Kiri <bredcorn@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/23706
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
package/system/mtd/src/mtd.c