提交 6cf21792 编写于 作者: A Arnd Bergmann 提交者: Arnd Bergmann

[POWERPC] spufs: fix memory leak on coredump

Dynamically allocated read/write buffer in spufs_arch_write_note() will
not be freed. Convert it to get_free_page at the same time.

Cc: Akinobu Mita <mita@fixstars.com>
Signed-off-by: NArnd Bergmann <arnd.bergmann@de.ibm.com>
上级 d3764397
...@@ -169,12 +169,12 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i, ...@@ -169,12 +169,12 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i,
struct spu_context *ctx; struct spu_context *ctx;
loff_t pos = 0; loff_t pos = 0;
int sz, dfd, rc, total = 0; int sz, dfd, rc, total = 0;
const int bufsz = 4096; const int bufsz = PAGE_SIZE;
char *name; char *name;
char fullname[80], *buf; char fullname[80], *buf;
struct elf_note en; struct elf_note en;
buf = kmalloc(bufsz, GFP_KERNEL); buf = (void *)get_zeroed_page(GFP_KERNEL);
if (!buf) if (!buf)
return; return;
...@@ -187,9 +187,8 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i, ...@@ -187,9 +187,8 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i,
sz = spufs_coredump_read[i].size; sz = spufs_coredump_read[i].size;
ctx = ctx_info->ctx; ctx = ctx_info->ctx;
if (!ctx) { if (!ctx)
return; goto out;
}
sprintf(fullname, "SPU/%d/%s", dfd, name); sprintf(fullname, "SPU/%d/%s", dfd, name);
en.n_namesz = strlen(fullname) + 1; en.n_namesz = strlen(fullname) + 1;
...@@ -197,23 +196,25 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i, ...@@ -197,23 +196,25 @@ static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i,
en.n_type = NT_SPU; en.n_type = NT_SPU;
if (!spufs_dump_write(file, &en, sizeof(en))) if (!spufs_dump_write(file, &en, sizeof(en)))
return; goto out;
if (!spufs_dump_write(file, fullname, en.n_namesz)) if (!spufs_dump_write(file, fullname, en.n_namesz))
return; goto out;
if (!spufs_dump_seek(file, roundup((unsigned long)file->f_pos, 4))) if (!spufs_dump_seek(file, roundup((unsigned long)file->f_pos, 4)))
return; goto out;
do { do {
rc = do_coredump_read(i, ctx, buf, bufsz, &pos); rc = do_coredump_read(i, ctx, buf, bufsz, &pos);
if (rc > 0) { if (rc > 0) {
if (!spufs_dump_write(file, buf, rc)) if (!spufs_dump_write(file, buf, rc))
return; goto out;
total += rc; total += rc;
} }
} while (rc == bufsz && total < sz); } while (rc == bufsz && total < sz);
spufs_dump_seek(file, roundup((unsigned long)file->f_pos spufs_dump_seek(file, roundup((unsigned long)file->f_pos
- total + sz, 4)); - total + sz, 4));
out:
free_page((unsigned long)buf);
} }
static void spufs_arch_write_notes(struct file *file) static void spufs_arch_write_notes(struct file *file)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册