Skip to content

Commit

Permalink
Merge pull request #1655 from eriksjolund/reduce-memory-consumption-i…
Browse files Browse the repository at this point in the history
…n-safe_readlinkat

utils: reduce memory consumption in safe_readlinkat
  • Loading branch information
giuseppe authored Feb 3, 2025
2 parents a029af2 + b548479 commit f7e0b65
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ safe_openat (int dirfd, const char *rootfs, size_t rootfs_len, const char *path,
ssize_t
safe_readlinkat (int dfd, const char *name, char **buffer, ssize_t hint, libcrun_error_t *err)
{
/* Add 1 to make room for the NUL terminator. */
ssize_t buf_size = hint > 0 ? hint + 1 : 512;
cleanup_free char *tmp_buf = NULL;
ssize_t size;
Expand All @@ -429,8 +430,7 @@ safe_readlinkat (int dfd, const char *name, char **buffer, ssize_t hint, libcrun
if (tmp_buf != NULL)
buf_size += 256;

/* Allocate an extra byte so the buffer can be NUL terminated. */
tmp_buf = xrealloc (tmp_buf, buf_size + 1);
tmp_buf = xrealloc (tmp_buf, buf_size);

size = readlinkat (dfd, name, tmp_buf, buf_size);
if (UNLIKELY (size < 0))
Expand Down

0 comments on commit f7e0b65

Please sign in to comment.