--- apps/app_voicemail.c +++ apps/app_voicemail.c @@ -7397,6 +7397,9 @@ /* If ADSI is supported, setup login screen */ adsi_begin(chan, &useadsi); + if (!valid) + goto out; + #ifdef IMAP_STORAGE pthread_once(&ts_vmstate.once, ts_vmstate.key_init); pthread_setspecific(ts_vmstate.key, &vms); @@ -7407,9 +7410,6 @@ vmstate_insert(&vms); init_vm_state(&vms); #endif - if (!valid) - goto out; - if (!(vms.deleted = ast_calloc(vmu->maxmsg, sizeof(int)))) { /* TODO: Handle memory allocation failure */ } @@ -7824,7 +7824,8 @@ } /* before we delete the state, we should copy pertinent info * back to the persistent model */ - vmstate_delete(&vms); + if (vmu) + vmstate_delete(&vms); #endif if (vmu) free_user(vmu);