diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-07-08 00:26:24 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-07-07 17:42:10 -0700 |
commit | 94d6e5d851dd72466ab6c7447391b0237040818b (patch) | |
tree | 6bf917009e56e3de45216dab3cb902b5dbe30962 /core/linux.c | |
parent | 2de5b95acf65cf67db43783b9d308bd097fd7141 (diff) | |
download | subsurface-94d6e5d851dd72466ab6c7447391b0237040818b.tar.gz |
save-git: allocate user_info members on the heap
subsurface_user_info() only works on Linux (linux.c),
but it doesn't allocate values on the heap.
Solve this ownership problem by always allocating
.name and .email on the heap in subsurface_user_info()
and freeing in the caller.
If subsurface_user_info() did not modify any of the
values from NULL, use default ones, but allocate them
on the heap too.
Ref #1346
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'core/linux.c')
-rw-r--r-- | core/linux.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/core/linux.c b/core/linux.c index b8d88e9e5..07d178cb0 100644 --- a/core/linux.c +++ b/core/linux.c @@ -39,7 +39,7 @@ void subsurface_user_info(struct user_info *user) if (pwd) { if (!empty_string(pwd->pw_gecos)) - user->name = pwd->pw_gecos; + user->name = strdup(pwd->pw_gecos); if (!username) username = pwd->pw_name; } @@ -48,8 +48,7 @@ void subsurface_user_info(struct user_info *user) struct membuffer mb = {}; gethostname(hostname, sizeof(hostname)); put_format(&mb, "%s@%s", username, hostname); - user->email = mb_cstring(&mb); - free_buffer(&mb); + user->email = mb_cstring(&mb); // 'email' is heap allocated } } |