diff options
author | Brandon Philips <brandon@ifup.org> | 2009-12-17 17:15:57 -0800 |
---|---|---|
committer | Brandon Philips <brandon@ifup.org> | 2009-12-17 17:22:09 -0800 |
commit | 972b42a67393f762936e74d3ce929914181f5f28 (patch) | |
tree | fcf5ccee8cfe53efebdce4bb6646710ce34c51b0 | |
parent | 9d115d7fa254a1e40755993fa4569b8f42829211 (diff) | |
download | attr-972b42a67393f762936e74d3ce929914181f5f28.tar.gz |
libattr: fix memory leak in attr_copy_action()
stanse found that attr_copy_action returns before freeing the memory
allocated for text.
Move fopen() above the malloc so this is not a problem.
Fixes this bug:
https://bugzilla.novell.com/show_bug.cgi?id=564735
Signed-off-by: Brandon Philips <bphilips@suse.de>
-rw-r--r-- | libattr/attr_copy_action.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/libattr/attr_copy_action.c b/libattr/attr_copy_action.c index 0d7aca5..dc94224 100644 --- a/libattr/attr_copy_action.c +++ b/libattr/attr_copy_action.c @@ -53,7 +53,7 @@ free_attr_actions(void) static int attr_parse_attr_conf(struct error_context *ctx) { - char *text, *t; + char *text = NULL, *t; size_t size_guess = 4096, len; FILE *file; char *pattern = NULL; @@ -64,15 +64,16 @@ attr_parse_attr_conf(struct error_context *ctx) return 0; repeat: - text = malloc(size_guess + 1); - if (!text) - goto fail; - if ((file = fopen(ATTR_CONF, "r")) == NULL) { if (errno == ENOENT) return 0; goto fail; } + + text = malloc(size_guess + 1); + if (!text) + goto fail; + len = fread(text, 1, size_guess, file); if (ferror(file)) goto fail; |