fix assert for non-existing MIDI patch-names
[ardour.git] / libs / pbd / mountpoint.cc
index c1bcb375f3a67f84d1a4d4cc8febb827f6a84de7..46cea42e0a2d0adf4130f2981b1a5110a50585c0 100644 (file)
 */
 
 #include <cstdio>
+#include <cstring>
 #include <string>
+#include <cstring>
 #include <limits.h>
 
-#include <pbd/mountpoint.h>
+#include "pbd/mountpoint.h"
 
 using std::string;
 
-#if HAVE_GETMNTENT
+#ifdef WAF_BUILD
+#include "libpbd-config.h"
+#endif
+
+#ifdef HAVE_GETMNTENT
 #include <mntent.h>
 
 struct mntent_sorter {
@@ -104,8 +110,13 @@ mountpoint (string path)
        const char *cpath = path.c_str();
        char best[PATH_MAX+1];
        
+       /* From the manpage, under "BUGS" : "The memory allocated by getmntinfo() cannot be free(3)'d by the 
+          application."
+          
+          Thus: we do NOT try to free memory allocated by getmntinfo()
+       */
+
        if ((count = getmntinfo(&mntbufp, MNT_NOWAIT)) == 0) {
-               free(mntbufp);
                return "\0";
        }
 
@@ -129,7 +140,6 @@ mountpoint (string path)
 
                if (cpath[matchlen] == '\0') {
                        snprintf(best, sizeof(best), "%s", mntbufp[i].f_mntonname);
-                       free(mntbufp);
                        return best;
 
                } else {
@@ -140,8 +150,6 @@ mountpoint (string path)
                        }
                }
        }
-
-       free(mntbufp);
        
        return best;
 }