refactor: use libgit free() functions instead of calloc()

This commit is contained in:
Aleksey Kulikov 2021-08-05 20:07:00 +03:00
parent 4f851bc2e5
commit 2477b4efd8
14 changed files with 30 additions and 21 deletions

View file

@ -284,3 +284,6 @@ void deleteMultivar(
calloc.free(name);
calloc.free(regexpC);
}
/// Free the configuration and its associated memory and files.
void free(Pointer<git_config> cfg) => libgit2.git_config_free(cfg);

View file

@ -215,3 +215,6 @@ bool isValidName(String name) {
calloc.free(refname);
return result == 1 ? true : false;
}
/// Free the given reference.
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);

View file

@ -446,3 +446,6 @@ Pointer<Pointer<git_object>> revParseSingle(
return out;
}
/// Free a previously allocated repository.
void free(Pointer<git_repository> repo) => libgit2.git_repository_free(repo);

View file

@ -17,7 +17,7 @@ class Config {
/// [path] should point to single on-disk file; it's expected to be a native
/// Git config file following the default Git config syntax (see man git-config).
///
/// [Config] object should be closed with [close] function to release allocated memory.
/// [Config] object should be closed with [free] function to release allocated memory.
Config.open({this.path}) {
libgit2.git_libgit2_init();
@ -145,8 +145,8 @@ class Config {
}
/// Releases memory allocated for config object.
void close() {
calloc.free(_configPointer);
void free() {
bindings.free(_configPointer);
libgit2.git_libgit2_shutdown();
}
}

View file

@ -138,7 +138,7 @@ class Reference {
/// Releases memory allocated for reference object.
void free() {
calloc.free(_refPointer);
bindings.free(_refPointer);
libgit2.git_libgit2_shutdown();
}
}

View file

@ -14,7 +14,7 @@ class Repository {
/// or to the working directory. For a bare repository, [path] should directly
/// point to the repository folder.
///
/// [Repository] object should be close with [close] function to release allocated memory.
/// [Repository] object should be close with [free] function to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Repository.open(String path) {
@ -237,8 +237,8 @@ class Repository {
String get workdir => bindings.workdir(_repoPointer);
/// Releases memory allocated for repository object.
void close() {
calloc.free(_repoPointer);
void free() {
bindings.free(_repoPointer);
libgit2.git_libgit2_shutdown();
}