[ncplayer] leaks on error paths

pull/2320/head
nick black 3 years ago
parent 41a657f804
commit a9ed0a1092
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -50,6 +50,7 @@ auto perframe(struct ncvisual* ncv, struct ncvisual_options* vopts,
NotCurses &nc = NotCurses::get_instance(); NotCurses &nc = NotCurses::get_instance();
auto start = static_cast<struct timespec*>(ncplane_userptr(vopts->n)); auto start = static_cast<struct timespec*>(ncplane_userptr(vopts->n));
if(!start){ if(!start){
// FIXME how do we get this free()d at the end?
start = static_cast<struct timespec*>(malloc(sizeof(struct timespec))); start = static_cast<struct timespec*>(malloc(sizeof(struct timespec)));
clock_gettime(CLOCK_MONOTONIC, start); clock_gettime(CLOCK_MONOTONIC, start);
ncplane_set_userptr(vopts->n, start); ncplane_set_userptr(vopts->n, start);
@ -370,11 +371,11 @@ int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
nopts.name = "play"; nopts.name = "play";
nopts.resizecb = ncplane_resize_marginalized; nopts.resizecb = ncplane_resize_marginalized;
nopts.flags = NCPLANE_OPTION_MARGINALIZED; nopts.flags = NCPLANE_OPTION_MARGINALIZED;
ncplane* n = nullptr;
for(auto i = 0 ; i < argc ; ++i){ for(auto i = 0 ; i < argc ; ++i){
std::unique_ptr<Visual> ncv; std::unique_ptr<Visual> ncv;
ncv = std::make_unique<Visual>(argv[i]); ncv = std::make_unique<Visual>(argv[i]);
auto n = ncplane_create(*stdn, &nopts); if((n = ncplane_create(*stdn, &nopts)) == nullptr){
if(!n){
return -1; return -1;
} }
ncplane_move_bottom(n); ncplane_move_bottom(n);
@ -409,8 +410,7 @@ int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
if(displaytime < 0){ if(displaytime < 0){
stdn->printf(0, NCAlign::Center, "press space to advance"); stdn->printf(0, NCAlign::Center, "press space to advance");
if(!nc.render()){ if(!nc.render()){
ncplane_destroy(n); goto err;
return -1;
} }
ncinput ni; ncinput ni;
do{ do{
@ -435,8 +435,7 @@ int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
}else if(ni.id == NCKey::Resize){ }else if(ni.id == NCKey::Resize){
--i; // rerun with the new size --i; // rerun with the new size
if(!nc.refresh(&dimy, &dimx)){ if(!nc.refresh(&dimy, &dimx)){
ncplane_destroy(n); goto err;
return -1;
} }
break; break;
} }
@ -455,13 +454,17 @@ int rendered_mode_player_inner(NotCurses& nc, int argc, char** argv,
}while(loop && r == 0); }while(loop && r == 0);
if(r < 0){ // positive is intentional abort if(r < 0){ // positive is intentional abort
std::cerr << "Error while playing " << argv[i] << std::endl; std::cerr << "Error while playing " << argv[i] << std::endl;
ncplane_destroy(n); goto err;
return -1;
} }
free(ncplane_userptr(n)); free(ncplane_userptr(n));
ncplane_destroy(n); ncplane_destroy(n);
} }
return 0; return 0;
err:
free(ncplane_userptr(n));
ncplane_destroy(n);
return -1;
} }
int rendered_mode_player(int argc, char** argv, ncscale_e scalemode, int rendered_mode_player(int argc, char** argv, ncscale_e scalemode,

Loading…
Cancel
Save