[Libguestfs] [PATCH 09/13] syntax-check: fix prohibit_path_max_allocation check

Hu Tao
2014-09-23T09:20:35Z

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 daemon/inotify.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/daemon/inotify.c b/daemon/inotify.c
index 36e5ede..b847b7d 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -309,7 +309,7 @@ do_inotify_files (void)
   unsigned int i;
   FILE *fp = NULL;
   guestfs_int_inotify_event_list *events;
-  char buf[PATH_MAX];
+  char *buf = NULL;
   char tempfile[] = "/tmp/inotifyXXXXXX";
   int fd;
   char cmd[64];
@@ -361,6 +361,12 @@ do_inotify_files (void)
     return NULL;
   }

+  buf = malloc(PATH_MAX);
+  if (buf == NULL) {
+    reply_with_perror ("malloc");
+    goto error;
+  }
+
   while (fgets (buf, sizeof buf, fp) != NULL) {
     size_t len = strlen (buf);

@@ -374,6 +380,8 @@ do_inotify_files (void)
   fclose (fp); /* implicitly closes fd */
   fp = NULL;

+  free(buf);
+
   if (end_stringsbuf (&ret) == -1)
     goto error;

@@ -384,6 +392,8 @@ do_inotify_files (void)
   if (fp != NULL)
     fclose (fp);

+  free (buf);
+
   unlink (tempfile);
   return NULL;
 }
--
1.9.3