In the Linux kernel, the following vulnerability has been resolved: ubifs: Fix memleak when insertoldidx() failed Following process will cause a memleak for copied up znode: dirtycowznode zn = copyznode(c, znode); err = insertoldidx(c, zbr->lnum, zbr->offs); if (unlikely(err)) return ERRPTR(err); // No one refers to zn. Fetch a reproducer in [Link]. Function copyznode() is split into 2 parts: resource allocation and znode replacement, insertoldidx() is split in similar way, so resource cleanup could be done in error handling path without corrupting metadata(mem & disk). It's okay that old index inserting is put behind of addidxdirt(), old index is used in layoutlebingaps(), so the two processes do not depend on each other.