diff --git a/app.c b/app.c
index 6a4995609a7407597d368cf6176092e915b26ea0..db1567dfc160da64f3a536c76d6bf46e3771f267 100644
--- a/app.c
+++ b/app.c
@@ -931,11 +931,13 @@ enum AST_LOCK_RESULT ast_lock_path(const char *path)
 	start = time(NULL);
 	while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
 		usleep(1);
+
+	unlink(fs);
+
 	if (res) {
 		ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
 		return AST_LOCK_TIMEOUT;
 	} else {
-		unlink(fs);
 		ast_log(LOG_DEBUG, "Locked path '%s'\n", path);
 		return AST_LOCK_SUCCESS;
 	}
@@ -944,11 +946,21 @@ enum AST_LOCK_RESULT ast_lock_path(const char *path)
 int ast_unlock_path(const char *path)
 {
 	char *s;
-	if (!(s = alloca(strlen(path) + 10)))
+	int res;
+
+	if (!(s = alloca(strlen(path) + 10))) {
+		ast_log(LOG_WARNING, "Out of memory!\n");
 		return -1;
+	}
+
 	snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
-	ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
-	return unlink(s);
+
+	if ((res = unlink(s)))
+		ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno));
+	else
+		ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
+
+	return res;
 }
 
 int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path) 
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index e0a7f3b2152e0e92f21b2266705425476496e04e..210201721ef19d0e17fc7bb5a1a9a25ef6433f3c 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -2650,7 +2650,8 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
 				} else if (ast_fileexists(tmptxtfile, NULL, NULL) <= 0) {
 					if (option_debug) 
 						ast_log(LOG_DEBUG, "The recorded media file is gone, so we should remove the .txt file too!\n");
-					unlink(tmptxtfile);	
+					unlink(tmptxtfile);
+					ast_unlock_path(dir);
 				} else {
 					for (;;) {
 						make_file(fn, sizeof(fn), dir, msgnum);