diff options
-rw-r--r-- | apps/app_voicemail.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 3f7f1c220..c72f5311b 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -3031,7 +3031,10 @@ static int last_message_index(struct ast_vm_user *vmu, char *dir) * doing a stat repeatedly on a predicted sequence. I suspect this * is partially due to stat(2) internally doing a readdir(2) itself to * find each file. */ - msgdir = opendir(dir); + if (!(msgdir = opendir(dir))) { + return -1; + } + while ((msgdirent = readdir(msgdir))) { if (sscanf(msgdirent->d_name, "msg%30d", &msgdirint) == 1 && msgdirint < MAXMSGLIMIT) map[msgdirint] = 1; |