refactor!: use Finalizer to automatically free allocated memory for objects (#48)

BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
Aleksey Kulikov 2022-04-28 11:04:48 +03:00 committed by GitHub
parent 94c40f9a94
commit a3213a88a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 2278 additions and 2595 deletions

View file

@ -55,13 +55,15 @@ Pointer<git_submodule> lookup({
final error = libgit2.git_submodule_lookup(out, repoPointer, nameC);
final result = out.value;
calloc.free(out);
calloc.free(nameC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
return result;
}
}
@ -130,11 +132,14 @@ Pointer<git_repository> open(Pointer<git_submodule> submodule) {
final out = calloc<Pointer<git_repository>>();
final error = libgit2.git_submodule_open(out, submodule);
final result = out.value;
calloc.free(out);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
return result;
}
}
@ -165,14 +170,16 @@ Pointer<git_submodule> addSetup({
useGitlinkC,
);
final result = out.value;
calloc.free(out);
calloc.free(urlC);
calloc.free(pathC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
return result;
}
}
@ -229,10 +236,11 @@ int status({
final nameC = name.toNativeUtf8().cast<Int8>();
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
final result = out.value;
calloc.free(out);
calloc.free(nameC);
final result = out.value;
calloc.free(out);
return result;
}