summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/dive.h4
-rw-r--r--core/linux.c5
-rw-r--r--core/save-git.c17
3 files changed, 14 insertions, 12 deletions
diff --git a/core/dive.h b/core/dive.h
index 1ce180238..1e694e271 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -712,8 +712,8 @@ int cylinderuse_from_text(const char *text);
struct user_info {
- const char *name;
- const char *email;
+ char *name;
+ char *email;
};
extern void subsurface_user_info(struct user_info *);
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
}
}
diff --git a/core/save-git.c b/core/save-git.c
index 3780399a0..8e5891969 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -1054,16 +1054,19 @@ static int get_authorship(git_repository *repo, git_signature **authorp)
if (git_signature_default(authorp, repo) == 0)
return 0;
#endif
- /* Default name information, with potential OS overrides */
- struct user_info user = {
- .name = "Subsurface",
- .email = "subsurface-app-account@subsurface-divelog.org"
- };
-
+ /* try to fetch the user info from the OS, otherwise use default values. */
+ struct user_info user = { .name = NULL, .email = NULL };
subsurface_user_info(&user);
+ if (!user.name)
+ user.name = strdup("Subsurface");
+ if (!user.email)
+ user.email = strdup("subsurface-app-account@subsurface-divelog.org");
/* git_signature_default() is too recent */
- return git_signature_now(authorp, user.name, user.email);
+ int ret = git_signature_now(authorp, user.name, user.email);
+ free((void *)user.name);
+ free((void *)user.email);
+ return ret;
}
static void create_commit_message(struct membuffer *msg, bool create_empty)