mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:13:24 +00:00
git access: add proper cleanup function for git_info
We had various random "free parts of the git info" left-overs from when we passed down the git repo data ad-hoc. Get rid of it, and replace it with just doing a 'cleanup_git_info()' that does the final cleanup of it all. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
96337dbbcf
commit
e33680c336
9 changed files with 28 additions and 15 deletions
|
@ -306,11 +306,15 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
* Opening the cloud storage repository failed for some reason
|
||||
* give up here and don't send errors about git repositories
|
||||
*/
|
||||
if (info.is_subsurface_cloud)
|
||||
if (info.is_subsurface_cloud) {
|
||||
cleanup_git_info(&info);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return git_load_dives(&info, table, trips, sites, devices, filter_presets);
|
||||
ret = git_load_dives(&info, table, trips, sites, devices, filter_presets);
|
||||
cleanup_git_info(&info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = readfile(filename, &mem)) < 0) {
|
||||
|
|
|
@ -1009,6 +1009,17 @@ static void extract_username(struct git_info *info, char *url)
|
|||
prefs.cloud_storage_email_encoded = strdup(info->username);
|
||||
}
|
||||
|
||||
void cleanup_git_info(struct git_info *info)
|
||||
{
|
||||
if (info->repo)
|
||||
git_repository_free(info->repo);
|
||||
free((void *)info->url);
|
||||
free((void *)info->branch);
|
||||
free((void *)info->username);
|
||||
free((void *)info->localdir);
|
||||
memset(info, 0, sizeof(*info));
|
||||
}
|
||||
|
||||
/*
|
||||
* If it's not a git repo, return NULL. Be very conservative.
|
||||
*
|
||||
|
|
|
@ -48,6 +48,7 @@ extern int git_load_dives(struct git_info *, struct dive_table *table, struct tr
|
|||
struct filter_preset_table *filter_presets);
|
||||
extern const char *get_sha(git_repository *repo, const char *branch);
|
||||
extern int do_git_save(struct git_info *, bool select_only, bool create_empty);
|
||||
extern void cleanup_git_info(struct git_info *);
|
||||
extern const char *saved_git_id;
|
||||
extern bool git_local_only;
|
||||
extern bool git_remote_sync_successful;
|
||||
|
|
|
@ -1960,8 +1960,6 @@ int git_load_dives(struct git_info *info, struct dive_table *table, struct trip_
|
|||
if (!info->repo)
|
||||
return report_error("Unable to open git repository '%s[%s]'", info->url, info->branch);
|
||||
ret = do_git_load(info->repo, info->branch, &state);
|
||||
git_repository_free(info->repo);
|
||||
free((void *)info->branch);
|
||||
finish_active_dive(&state);
|
||||
finish_active_trip(&state);
|
||||
return ret;
|
||||
|
|
|
@ -1362,8 +1362,6 @@ int do_git_save(struct git_info *info, bool select_only, bool create_empty)
|
|||
|
||||
int git_save_dives(struct git_info *info, bool select_only)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* FIXME!! This open_git_repository() will
|
||||
* sync with the cloud. That is NOT what
|
||||
|
@ -1389,8 +1387,5 @@ int git_save_dives(struct git_info *info, bool select_only)
|
|||
if (!open_git_repository(info))
|
||||
report_error(translate("gettextFromC", "Failed to save dives to %s[%s] (%s)"), info->url, info->branch, strerror(errno));
|
||||
|
||||
ret = do_git_save(info, select_only, false);
|
||||
git_repository_free(info->repo);
|
||||
free((void *)info->branch);
|
||||
return ret;
|
||||
return do_git_save(info, select_only, false);
|
||||
}
|
||||
|
|
|
@ -826,8 +826,11 @@ int save_dives_logic(const char *filename, const bool select_only, bool anonymiz
|
|||
FILE *f;
|
||||
int error = 0;
|
||||
|
||||
if (is_git_repository(filename, &info))
|
||||
return git_save_dives(&info, select_only);
|
||||
if (is_git_repository(filename, &info)) {
|
||||
error = git_save_dives(&info, select_only);
|
||||
cleanup_git_info(&info);
|
||||
return error;
|
||||
}
|
||||
|
||||
save_dives_buffer(&buf, select_only, anonymize);
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ void print_files()
|
|||
} else {
|
||||
printf("Unable to get local git directory\n");
|
||||
}
|
||||
cleanup_git_info(&info);
|
||||
printf("Cloud URL: %s\n", filename);
|
||||
free((void *)filename);
|
||||
char *tmp = hashfile_name_string();
|
||||
|
|
|
@ -769,6 +769,8 @@ void QMLManager::loadDivesWithValidCredentials()
|
|||
}
|
||||
consumeFinishedLoad();
|
||||
}
|
||||
cleanup_git_info(&info);
|
||||
|
||||
setLoadFromCloud(true);
|
||||
|
||||
// if we came from local storage mode, let's merge the local data into the local cache
|
||||
|
|
|
@ -66,9 +66,7 @@ static void localRemoteCleanup()
|
|||
// and since this will have created a local repo, remove that one, again so the tests start clean
|
||||
QCOMPARE(localCacheDirectory.removeRecursively(), true);
|
||||
|
||||
free((void *)info.branch);
|
||||
free((void *)info.url);
|
||||
git_repository_free(info.repo);
|
||||
cleanup_git_info(&info);
|
||||
}
|
||||
|
||||
void TestGitStorage::initTestCase()
|
||||
|
|
Loading…
Add table
Reference in a new issue