Index: trunk/src/VBox/Devices/Audio/AudioMixer.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/AudioMixer.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/AudioMixer.cpp	(revision 87861)
@@ -1510,23 +1510,16 @@
         DrvAudioHlpFileClose(pSink->Dbg.pFile);
 
-        char szTemp[RTPATH_MAX];
-        int rc2 = RTPathTemp(szTemp, sizeof(szTemp));
+        char szName[64];
+        RTStrPrintf(szName, sizeof(szName), "MixerSink-%s", pSink->pszName);
+
+        char szFile[RTPATH_MAX];
+        int rc2 = DrvAudioHlpFileNameGet(szFile, RT_ELEMENTS(szFile), NULL /* Use temporary directory */, szName,
+                                         0 /* Instance */, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAGS_NONE);
         if (RT_SUCCESS(rc2))
         {
-            /** @todo Sanitize sink name. */
-
-            char szName[64];
-            RTStrPrintf(szName, sizeof(szName), "MixerSink-%s", pSink->pszName);
-
-            char szFile[RTPATH_MAX];
-            rc2 = DrvAudioHlpFileNameGet(szFile, RT_ELEMENTS(szFile), szTemp, szName,
-                                         0 /* Instance */, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAGS_NONE);
+            rc2 = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAGS_NONE,
+                                        &pSink->Dbg.pFile);
             if (RT_SUCCESS(rc2))
-            {
-                rc2 = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAGS_NONE,
-                                            &pSink->Dbg.pFile);
-                if (RT_SUCCESS(rc2))
-                    rc2 = DrvAudioHlpFileOpen(pSink->Dbg.pFile, PDMAUDIOFILE_DEFAULT_OPEN_FLAGS, &pSink->PCMProps);
-            }
+                rc2 = DrvAudioHlpFileOpen(pSink->Dbg.pFile, PDMAUDIOFILE_DEFAULT_OPEN_FLAGS, &pSink->PCMProps);
         }
     }
Index: trunk/src/VBox/Devices/Audio/DevHDA.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DevHDA.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DevHDA.cpp	(revision 87861)
@@ -2934,4 +2934,5 @@
 #  endif
 
+#  ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
             if (pThis->fDebugEnabled)
             {
@@ -2942,4 +2943,5 @@
                 RTFileClose(fh);
             }
+#  endif
 
 #  ifdef HDA_USE_DMA_ACCESS_HANDLER_WRITING
@@ -4823,5 +4825,5 @@
                                 N_("HDA configuration error: failed to read debugging enabled flag as boolean"));
 
-    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "DebugPathOut", &pThisCC->Dbg.pszOutPath, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH);
+    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "DebugPathOut", &pThisCC->Dbg.pszOutPath, NULL);
     if (RT_FAILURE(rc))
         return PDMDEV_SET_ERROR(pDevIns, rc,
Index: trunk/src/VBox/Devices/Audio/DevHDA.h
===================================================================
--- trunk/src/VBox/Devices/Audio/DevHDA.h	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DevHDA.h	(revision 87861)
@@ -271,5 +271,5 @@
         bool                    fEnabled;
         /** Path where to dump the debug output to.
-         *  Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH. */
+         *  Can be NULL, in which the system's temporary directory will be used then. */
         R3PTRTYPE(char *)       pszOutPath;
     } Dbg;
Index: trunk/src/VBox/Devices/Audio/DevIchAc97.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DevIchAc97.cpp	(revision 87861)
@@ -525,5 +525,5 @@
     bool                    afAlignment[7];
     /** Path where to dump the debug output to.
-     *  Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH. */
+     *  Can be NULL, in which the system's temporary directory will be used then. */
     R3PTRTYPE(char *)       pszOutPath;
 } AC97STATEDEBUG;
@@ -4177,5 +4177,5 @@
                                 N_("AC97 configuration error: failed to read debugging enabled flag as boolean"));
 
-    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "DebugPathOut", &pThisCC->Dbg.pszOutPath, VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH);
+    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "DebugPathOut", &pThisCC->Dbg.pszOutPath, NULL);
     if (RT_FAILURE(rc))
         return PDMDEV_SET_ERROR(pDevIns, rc,
Index: trunk/src/VBox/Devices/Audio/DrvAudio.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DrvAudio.cpp	(revision 87861)
@@ -2327,5 +2327,7 @@
         || !strlen(pCfg->Dbg.szPathOut))
     {
-        RTStrPrintf(pCfg->Dbg.szPathOut, sizeof(pCfg->Dbg.szPathOut), VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH);
+        rc2 = RTPathTemp(pCfg->Dbg.szPathOut, sizeof(pCfg->Dbg.szPathOut));
+        if (RT_FAILURE(rc2))
+            LogRel(("Audio: Error retrieving temporary directory, rc=%Rrc\n", rc2));
     }
 
Index: trunk/src/VBox/Devices/Audio/DrvAudio.h
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvAudio.h	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DrvAudio.h	(revision 87861)
@@ -109,6 +109,5 @@
         /** Whether audio debugging is enabled or not. */
         bool             fEnabled;
-        /** Where to store the debugging files.
-         *  Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH if not set. */
+        /** Where to store the debugging files. */
         char             szPathOut[RTPATH_MAX];
     } Dbg;
Index: trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp	(revision 87861)
@@ -1502,4 +1502,5 @@
  * @param   cchFile             Size (in characters) of the file name buffer.
  * @param   pszPath             Base path to use.
+ *                              If NULL or empty, the system's temporary directory will be used.
  * @param   pszName             A name for better identifying the file.
  * @param   uInstance           Device / driver instance which is using this file.
@@ -1512,5 +1513,5 @@
     AssertPtrReturn(pszFile, VERR_INVALID_POINTER);
     AssertReturn(cchFile,    VERR_INVALID_PARAMETER);
-    AssertPtrReturn(pszPath, VERR_INVALID_POINTER);
+    /* pszPath can be NULL. */
     AssertPtrReturn(pszName, VERR_INVALID_POINTER);
     /** @todo Validate fFlags. */
@@ -1518,8 +1519,27 @@
     int rc;
 
+    char *pszPathTmp = NULL;
+
     do
     {
+        if (   pszPath == NULL
+            || !strlen(pszPath))
+        {
+            char szTemp[RTPATH_MAX];
+            rc = RTPathTemp(szTemp, sizeof(szTemp));
+            if (RT_SUCCESS(rc))
+            {
+                pszPathTmp = RTStrDup(szTemp);
+            }
+            else
+                break;
+        }
+        else
+            pszPathTmp = RTStrDup(pszPath);
+
+        AssertPtrBreakStmt(pszPathTmp, rc = VERR_NO_MEMORY);
+
         char szFilePath[RTPATH_MAX];
-        rc = RTStrCopy(szFilePath, sizeof(szFilePath), pszPath);
+        rc = RTStrCopy(szFilePath, sizeof(szFilePath), pszPathTmp);
         AssertRCBreak(rc);
 
@@ -1592,4 +1612,6 @@
 
     } while (0);
+
+    RTStrFree(pszPathTmp);
 
     LogFlowFuncLeaveRC(rc);
Index: trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp
===================================================================
--- trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp	(revision 87857)
+++ trunk/src/VBox/Devices/Audio/DrvHostDebugAudio.cpp	(revision 87861)
@@ -134,28 +134,21 @@
 static int debugCreateFile(PDRVHOSTDEBUGAUDIO pDrv, PDEBUGAUDIOSTREAM pStreamDbg, bool fIn, PPDMAUDIOSTREAMCFG pCfg)
 {
-    char szTemp[RTPATH_MAX];
-    int rc = RTPathTemp(szTemp, sizeof(szTemp));
+    char szFile[RTPATH_MAX];
+    int rc = DrvAudioHlpFileNameGet(szFile, RT_ELEMENTS(szFile), NULL /* Use temporary directory */, fIn ? "DebugAudioIn" : "DebugAudioOut",
+                                    pDrv->pDrvIns->iInstance, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAGS_NONE);
     if (RT_SUCCESS(rc))
     {
-        char szFile[RTPATH_MAX];
-        rc = DrvAudioHlpFileNameGet(szFile, RT_ELEMENTS(szFile), szTemp, fIn ? "DebugAudioIn" : "DebugAudioOut",
-                                    pDrv->pDrvIns->iInstance, PDMAUDIOFILETYPE_WAV, PDMAUDIOFILENAME_FLAGS_NONE);
+        rc = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAGS_NONE, &pStreamDbg->pFile);
         if (RT_SUCCESS(rc))
         {
-            rc = DrvAudioHlpFileCreate(PDMAUDIOFILETYPE_WAV, szFile, PDMAUDIOFILE_FLAGS_NONE, &pStreamDbg->pFile);
-            if (RT_SUCCESS(rc))
-            {
-                rc = DrvAudioHlpFileOpen(pStreamDbg->pFile, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE,
-                                         &pCfg->Props);
-            }
-
-            if (RT_FAILURE(rc))
-                LogRel(("DebugAudio: Creating %sput file '%s' failed with %Rrc\n", fIn ? "in" : "out", szFile, rc));
+            rc = DrvAudioHlpFileOpen(pStreamDbg->pFile, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE,
+                                     &pCfg->Props);
         }
-        else
-            LogRel(("DebugAudio: Unable to build file name for temp dir '%s': %Rrc\n", szTemp, rc));
+
+        if (RT_FAILURE(rc))
+            LogRel(("DebugAudio: Creating %sput file '%s' failed with %Rrc\n", fIn ? "in" : "out", szFile, rc));
     }
     else
-        LogRel(("DebugAudio: Unable to retrieve temp dir: %Rrc\n", rc));
+        LogRel(("DebugAudio: Unable to build file name: %Rrc\n", rc));
 
     return rc;
