commit 9a1d7435894d96f76306bd47db368d52bc7096d3 from: Stefan Sperling via: Thomas Adam date: Thu Jun 23 14:09:35 2022 UTC fix a segfault in tog diff The f1 tempfile must always be created. Even if the initial diff has no objects on the left side, the view can be switched to a different diff which does have objects on both sides. When that happened, tog crashed. (To reproduce: open tog in got.git, hit G, hit Enter, hit <) commit - c31666ae2d9d83148e3a726b077fb0756d807a4d commit + 9a1d7435894d96f76306bd47db368d52bc7096d3 blob - ad57666926b9f1cab97352254661551bba93066c blob + 1d279e38f6b3a34d9467747735abf31682c3c3af --- tog/tog.c +++ tog/tog.c @@ -3839,11 +3839,6 @@ open_diff_view(struct tog_view *view, struct got_objec s->id1 = got_object_id_dup(id1); if (s->id1 == NULL) return got_error_from_errno("got_object_id_dup"); - s->f1 = got_opentemp(); - if (s->f1 == NULL) { - err = got_error_from_errno("got_opentemp"); - goto done; - } } else s->id1 = NULL; @@ -3853,6 +3848,12 @@ open_diff_view(struct tog_view *view, struct got_objec goto done; } + s->f1 = got_opentemp(); + if (s->f1 == NULL) { + err = got_error_from_errno("got_opentemp"); + goto done; + } + s->f2 = got_opentemp(); if (s->f2 == NULL) { err = got_error_from_errno("got_opentemp");