mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
2de5b95acf
commit
94d6e5d851
3 changed files with 14 additions and 12 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue