diff options
author | Jim Meyering <jim@meyering.net> | 2004-04-18 14:58:51 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-04-18 14:58:51 +0000 |
commit | 544a43b5f7c93298abccb3ccc6ced841bf6923a9 (patch) | |
tree | 15fcfabe43594f18265876809cdb98c956076482 /src | |
parent | d9588b16a08e9a5dc43409d83677373fdc21c2ae (diff) | |
download | coreutils-544a43b5f7c93298abccb3ccc6ced841bf6923a9.tar.xz |
(full_filename_): Don't leak upon failed realloc.
Diffstat (limited to 'src')
-rw-r--r-- | src/remove.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/remove.c b/src/remove.c index 4672e8a93..d9fb21796 100644 --- a/src/remove.c +++ b/src/remove.c @@ -290,10 +290,10 @@ full_filename_ (Dirstack_state const *ds, const char *filename) error involving a file name to be expanded here wouldn't ever be issued. Use realloc and fall back on using a static buffer if memory allocation fails. */ - buf = realloc (buf, n_bytes_needed); + char *new_buf = realloc (buf, n_bytes_needed); n_allocated = n_bytes_needed; - if (buf == NULL) + if (new_buf == NULL) { #define SBUF_SIZE 512 #define ELLIPSES_PREFIX "[...]" @@ -302,6 +302,7 @@ full_filename_ (Dirstack_state const *ds, const char *filename) size_t len; char *p; + free (buf); len = right_justify (static_buf, SBUF_SIZE, filename, filename_len + 1, &p, &truncated); right_justify (static_buf, len, dir_name, dir_len, &p, &truncated); @@ -312,6 +313,8 @@ full_filename_ (Dirstack_state const *ds, const char *filename) } return p; } + + buf = new_buf; } if (filename_len == 1 && *filename == '.' && dir_len) |