commit - f2e80f4b6d7a56834b6c44f055317c88c833d277
commit + 6402fb3cc1e54689a0b577e5958bf75a5a7e798b
blob - 35b21af9e318560aaca023f05525b854d82e4b56
blob + a506816c409702b75d36358f67e56799c415fb42
--- got/got.c
+++ got/got.c
}
id = got_object_get_id(obj);
- if (id == NULL)
- return got_error_from_errno();
pid = got_object_get_id(pobj);
- if (pid == NULL) {
- err = got_error_from_errno();
- free(id);
- return err;
- }
-
*changed = (got_object_id_cmp(id, pid) != 0);
got_object_close(pobj);
- free(id);
- free(pid);
return NULL;
}
start_commit);
if (error != NULL)
return error;
- id = got_object_get_id(obj);
+ id = got_object_id_dup(got_object_get_id(obj));
if (id == NULL)
error = got_error_from_errno();
}
{
const struct got_error *error;
struct got_repository *repo = NULL;
- struct got_object_id *id1 = NULL, *id2 = NULL;
struct got_object *obj1 = NULL, *obj2 = NULL;
char *repo_path = NULL;
char *obj_id_str1 = NULL, *obj_id_str2 = NULL;
goto done;
error = got_object_open_by_id_str(&obj1, repo, obj_id_str1);
- if (error == NULL) {
- id1 = got_object_get_id(obj1);
- if (id1 == NULL)
- error = got_error_from_errno();
- }
- if (error != NULL)
+ if (error)
goto done;
error = got_object_open_by_id_str(&obj2, repo, obj_id_str2);
- if (error == NULL) {
- id2 = got_object_get_id(obj2);
- if (id2 == NULL)
- error = got_error_from_errno();
- }
- if (error != NULL)
+ if (error)
goto done;
if (got_object_get_type(obj1) != got_object_get_type(obj2)) {
got_object_close(obj1);
if (obj2)
got_object_close(obj2);
- if (id1)
- free(id1);
- if (id2)
- free(id2);
if (repo) {
const struct got_error *repo_error;
repo_error = got_repo_close(repo);
error = got_object_open_by_id_str(&obj, repo, commit_id_str);
if (error != NULL)
goto done;
- commit_id = got_object_get_id(obj);
+ commit_id = got_object_id_dup(got_object_get_id(obj));
if (commit_id == NULL)
error = got_error_from_errno();
got_object_close(obj);
blob - e59ee13190becb39193c375dab2908862dc51743
blob + 3b8ab2ca2d452058d45776035f263e51bf273ce6
--- include/got_object.h
+++ include/got_object.h
/*
* Get a newly allocated copy of an object's ID.
- * The caller should dispose of it with free(3).
+ * The caller must treat the ID as read-only and must not call free(3) on it.
+ * Use got_object_id_dup() to get a writable copy.
*/
struct got_object_id *got_object_get_id(struct got_object *);
blob - e0a3cb4106c801ab364f7421d420e633af511524
blob + f3e4cc89ab7b9cd52cad9abd652fde93bb1bbcfb
--- lib/object.c
+++ lib/object.c
struct got_object_id *
got_object_get_id(struct got_object *obj)
{
- return got_object_id_dup(&obj->id);
+ return &obj->id;
}
const struct got_error *
blob - d7c5c6828911b898e727a0cf6de3c87c8dd9c406
blob + 1e419f4ae1d5eb9ccc0b34b5c9bbf6c10ddae989
--- tog/tog.c
+++ tog/tog.c
} else {
struct got_object_id *id, *pid;
id = got_object_get_id(obj);
- if (id == NULL) {
- err = got_error_from_errno();
- got_object_close(obj);
- got_object_close(pobj);
- break;
- }
pid = got_object_get_id(pobj);
- if (pid == NULL) {
- err = got_error_from_errno();
- free(id);
- got_object_close(obj);
- got_object_close(pobj);
- break;
- }
changed =
(got_object_id_cmp(id, pid) != 0);
got_object_close(pobj);
- free(id);
- free(pid);
}
}
got_object_close(obj);
struct got_object *obj;
error = got_object_open_by_id_str(&obj, repo, start_commit);
if (error == NULL) {
- start_id = got_object_get_id(obj);
+ start_id = got_object_id_dup(got_object_get_id(obj));
if (start_id == NULL)
error = got_error_from_errno();
goto done;
view->state.diff.id1 = obj1 ? got_object_get_id(obj1) : NULL;
view->state.diff.id2 = got_object_get_id(obj2);
- if (view->state.diff.id2 == NULL)
- return got_error_from_errno();
view->state.diff.f = f;
view->state.diff.first_displayed_line = 1;
view->state.diff.last_displayed_line = view->nlines;
if (view->state.diff.f && fclose(view->state.diff.f) == EOF)
err = got_error_from_errno();
- free(view->state.diff.id1);
- free(view->state.diff.id2);
return err;
}
if (pobj) {
got_object_close(pobj);
pobj = NULL;
- }
- if (id == NULL) {
- err = got_error_from_errno();
- break;
}
- err = got_object_qid_alloc(
- &s->blamed_commit, id);
- free(id);
+ err = got_object_qid_alloc(&s->blamed_commit, id);
if (err)
goto done;
SIMPLEQ_INSERT_HEAD(&s->blamed_commits,
error = got_object_open_by_id_str(&obj, repo, commit_id_str);
if (error != NULL)
goto done;
- commit_id = got_object_get_id(obj);
+ commit_id = got_object_id_dup(got_object_get_id(obj));
if (commit_id == NULL)
error = got_error_from_errno();
got_object_close(obj);
struct got_object *obj;
error = got_object_open_by_id_str(&obj, repo, commit_id_arg);
if (error == NULL) {
- commit_id = got_object_get_id(obj);
+ commit_id = got_object_id_dup(got_object_get_id(obj));
if (commit_id == NULL)
error = got_error_from_errno();
}