Index: video_freebsd.c
===================================================================
--- video_freebsd.c	(revisión: 452)
+++ video_freebsd.c	(copia de trabajo)
@@ -684,7 +684,7 @@
     /* That is the buffer size for capture images ,
      so is dependent of color space of input format / FIXME */
 
-    viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char *));
+    viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char));
     viddev->v4l_fmt = VIDEO_PALETTE_YUV420P;
     
 
Index: video_freebsd.h
===================================================================
--- video_freebsd.h	(revisión: 452)
+++ video_freebsd.h	(copia de trabajo)
@@ -12,7 +12,9 @@
 
 #ifndef WITHOUT_V4L
 
-#ifdef OLD_BKTR
+#ifdef __NetBSD__
+#include <dev/ic/bt8xx.h>
+#elif defined(OLD_BKTR)
 #include <machine/ioctl_meteor.h>
 #include <machine/ioctl_bt848.h>
 #else
@@ -20,7 +22,6 @@
 #include <dev/bktr/ioctl_bt848.h>
 #endif
 
-
 #endif
 
 /* bktr (video4linux) stuff FIXME more modes not only these */
Index: configure.in
===================================================================
--- configure.in	(revisión: 452)
+++ configure.in	(copia de trabajo)
@@ -1,6 +1,6 @@
 # Process this file with autoconf to produce a configure script
 
-AC_INIT(motion, esyscmd(['./version.sh']))
+AC_INIT(motion, "3.2.11.1")
 AC_CONFIG_SRCDIR([motion.c])
 AC_CONFIG_HEADERS(config.h)
 
Index: motion.c
===================================================================
--- motion.c	(revisión: 452)
+++ motion.c	(copia de trabajo)
@@ -634,8 +634,7 @@
     /* create a reference frame */
     alg_update_reference_frame(cnt, RESET_REF_FRAME);
 
-#ifndef WITHOUT_V4L
-#if (!defined(BSD))
+#if !defined(WITHOUT_V4L) && !defined(BSD)
     /* open video loopback devices if enabled */
     if (cnt->conf.vidpipe) {
         if (cnt->conf.setup_mode)
@@ -661,8 +660,7 @@
             return -1;
         }
     }
-#endif /* BSD */
-#endif /*WITHOUT_V4L*/
+#endif /*WITHOUT_V4L && !BSD */
 
 #ifdef HAVE_MYSQL
     if (cnt->conf.mysql_db) {
@@ -2738,7 +2736,7 @@
 {
     int errno_save, n;
     char buf[1024];
-#if (!defined(BSD))
+#if (!defined(BSD)) && (!(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
     char msg_buf[100];
 #endif
     va_list ap;
@@ -2765,8 +2763,9 @@
 
     /* If errno_flag is set, add on the library error message */
     if (errno_flag) {
-        strcat(buf, ": ");
+        strncat(buf, ": ", 1024 - strlen(buf));
         n += 2;
+
         /*
          * this is bad - apparently gcc/libc wants to use the non-standard GNU
          * version of strerror_r, which doesn't actually put the message into
@@ -2774,13 +2773,15 @@
          */
 #if (defined(BSD))
         strerror_r(errno_save, buf + n, sizeof(buf) - n);    /* 2 for the ': ' */
+#elif (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
+        strerror_r(errno_save, buf + n, sizeof(buf) - n);
 #else
-        strcat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)));
+        strncat(buf, strerror_r(errno_save, msg_buf, sizeof(msg_buf)), 1024 - strlen(buf));
 #endif
     }
     /* If 'level' is not negative, send the message to the syslog */
     if (level >= 0)
-        syslog(level, buf);
+        syslog(level, "%s", buf);
 
     /* For printing to stderr we need to add a newline */
     strcat(buf, "\n");
Index: video.c
===================================================================
--- video.c	(revisión: 452)
+++ video.c	(copia de trabajo)
@@ -503,9 +503,9 @@
 
         while ((dirp=readdir(dir)) != NULL) {
             if (!strncmp(dirp->d_name, "video", 5)) {
-                strncpy(buffer, prefix, 255);
-                strncat(buffer, dirp->d_name, 255);
-                strncat(buffer, "/name", 255);
+                strncpy(buffer, prefix, sizeof(buffer));
+                strncat(buffer, dirp->d_name, sizeof(buffer) - strlen(buffer));
+                strncat(buffer, "/name", sizeof(buffer) - strlen(buffer));
                 if ((fd = open(buffer, O_RDONLY)) >= 0) {
                     if ((read(fd, buffer, sizeof(buffer)-1)) < 0) {
                         close(fd);
@@ -537,9 +537,9 @@
 
                     if (tnum < low) {
                         strcpy(buffer, "/dev/");
-                        strcat(buffer, dirp->d_name);
+                        strncat(buffer, dirp->d_name, sizeof(buffer) - strlen(buffer));
                         if ((tfd=open(buffer, O_RDWR)) >= 0) {
-                            strcpy(pipepath, buffer);
+                            strncpy(pipepath, buffer, sizeof(pipepath));
 
                             if (pipe_fd >= 0) 
                                 close(pipe_fd);
Index: motion.h
===================================================================
--- motion.h	(revisión: 452)
+++ motion.h	(copia de trabajo)
@@ -19,7 +19,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#ifndef __USE_GNU
 #define __USE_GNU
+#endif
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -37,7 +39,7 @@
 #include <stdint.h>
 
 #define _LINUX_TIME_H 1
-#if (!defined(WITHOUT_V4L)) && (!defined(BSD))
+#if !defined(WITHOUT_V4L) && !defined(BSD)
 #include <linux/videodev.h>
 #endif
 
Index: video.h
===================================================================
--- video.h	(revisión: 452)
+++ video.h	(copia de trabajo)
@@ -106,6 +106,6 @@
 void v4l2_close(struct video_dev *viddev);
 void v4l2_cleanup(struct video_dev *viddev);
 
-#endif
+#endif /* WITHOUT_V4L */
 
 #endif                /* _INCLUDE_VIDEO_H */
Index: event.c
===================================================================
--- event.c	(revisión: 452)
+++ event.c	(copia de trabajo)
@@ -12,7 +12,7 @@
 #include "ffmpeg.h"    /* must be first to avoid 'shadow' warning */
 #include "picture.h"    /* already includes motion.h */
 #include "event.h"
-#if (!defined(BSD)) 
+#if !defined(BSD) 
 #include "video.h"
 #endif
 
@@ -220,8 +220,7 @@
         webcam_put(cnt, img);
 }
 
-#ifndef WITHOUT_V4L
-#if (!defined(BSD))
+#if !defined(WITHOUT_V4L) && !defined(BSD)
 static void event_vid_putpipe(struct context *cnt, int type ATTRIBUTE_UNUSED,
             unsigned char *img, char *dummy ATTRIBUTE_UNUSED, void *devpipe,
             struct tm *tm ATTRIBUTE_UNUSED)
@@ -231,8 +230,7 @@
             motion_log(LOG_ERR, 1, "Failed to put image into video pipe");
     }
 }
-#endif /* BSD */
-#endif /* WITHOUT_V4L */
+#endif /* WITHOUT_V4L && !BSD */
 
 
 const char *imageext(struct context *cnt)
@@ -648,14 +646,12 @@
     EVENT_IMAGE_SNAPSHOT,
     event_image_snapshot
     },
-#ifndef WITHOUT_V4L
-#if (!defined(BSD))
+#if !defined(WITHOUT_V4L) && !defined(BSD)
     {
     EVENT_IMAGE | EVENT_IMAGEM,
     event_vid_putpipe
     },
-#endif /* BSD */
-#endif /* WITHOUT_V4L */
+#endif /* WITHOUT_V4L && !BSD */
     {
     EVENT_WEBCAM,
     event_webcam_put
Index: configure
===================================================================
--- configure	(revisión: 452)
+++ configure	(copia de trabajo)
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.61 for motion 3.2.11.
+# Generated by GNU Autoconf 2.61 for motion "3.2.11.1".
 #
 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
 # 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
@@ -572,8 +572,8 @@
 # Identity of this package.
 PACKAGE_NAME='motion'
 PACKAGE_TARNAME='motion'
-PACKAGE_VERSION='3.2.11'
-PACKAGE_STRING='motion 3.2.11'
+PACKAGE_VERSION='"3.2.11.1"'
+PACKAGE_STRING='motion "3.2.11.1"'
 PACKAGE_BUGREPORT=''
 
 ac_unique_file="motion.c"
@@ -1178,7 +1178,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures motion 3.2.11 to adapt to many kinds of systems.
+\`configure' configures motion "3.2.11.1" to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1239,7 +1239,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of motion 3.2.11:";;
+     short | recursive ) echo "Configuration of motion "3.2.11.1":";;
    esac
   cat <<\_ACEOF
 
@@ -1375,7 +1375,7 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-motion configure 3.2.11
+motion configure "3.2.11.1"
 generated by GNU Autoconf 2.61
 
 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1389,7 +1389,7 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by motion $as_me 3.2.11, which was
+It was created by motion $as_me "3.2.11.1", which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   $ $0 $@
@@ -8124,7 +8124,7 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by motion $as_me 3.2.11, which was
+This file was extended by motion $as_me "3.2.11.1", which was
 generated by GNU Autoconf 2.61.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -8173,7 +8173,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-motion config.status 3.2.11
+motion config.status "3.2.11.1"
 configured by $0, generated by GNU Autoconf 2.61,
   with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
 
Index: ffmpeg.c
===================================================================
--- ffmpeg.c	(revisión: 452)
+++ ffmpeg.c	(copia de trabajo)
@@ -164,7 +164,7 @@
     return write(fd, buf, size);
 }
 
-static offset_t file_seek(URLContext *h, offset_t pos, int whence)
+static int64_t file_seek(URLContext *h, int64_t pos, int whence)
 {
     int fd = (size_t)h->priv_data;
     return lseek(fd, pos, whence);
Index: CHANGELOG
===================================================================
--- CHANGELOG	(revisión: 452)
+++ CHANGELOG	(copia de trabajo)
@@ -1,3 +1,19 @@
+3.2.11.1 Sumary of Changes
+
+Bugfixes
+   * Fix Segfault on reload or quit for vloopback (maybe other v4l1 devices too) (Peter Holik)
+     http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2009x06x17x090603
+   * Fix fd leaks in external pipe. (Angel Carpintero)
+   * Avoid possible stack smashing in v4l_open_vidpipe(). (Angel Carpintero)
+   * Allow compile with OpenSuse ffmpeg package (15594svn-20081010)
+     http://www.lavrsen.dk/twiki/bin/view/Motion/SupportQuestion2008x10x25x070400 (Angel Carpintero)
+   * Fix warning for syslog().  (Angel Carpintero)
+   * Fix warning for __USE_GNU redefined (Peter Holik) 
+     http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2009x06x17x122137 (Peter Holik)
+   * Allow compile with NetBSD and make LP64 compliant video_freebsd.c (Andreas Wrede)
+
+   
+
 3.2.11 Summary of Changes
 
 Features
Index: CREDITS
===================================================================
--- CREDITS	(revisión: 452)
+++ CREDITS	(copia de trabajo)
@@ -405,6 +405,11 @@
      http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2008x06x19x123218
    * Get rid of ffmpeg-config in configure.in for debian.
    * Fix warning for x86_64 in conf.c using pointers LP64 compliant.
+   * Fix fd leaks in external pipe. 
+   * Avoid possible stack smashing in v4l_open_vidpipe(). 
+   * Allow compile with OpenSuse ffmpeg package (15594svn-20081010)
+     http://www.lavrsen.dk/twiki/bin/view/Motion/SupportQuestion2008x10x25x070400 
+   * Fix warning for syslog().
  
 Jared D
    * Change bayer2rgb24() to fix a problem with sn9c102 driver
@@ -535,6 +540,10 @@
      From mailing list 23 Dec 2005.
    * Avoid open file descriptor when connecting to network cameras fails 
      http://www.lavrsen.dk/twiki/bin/view/Motion/AvoidOpenfiledescriptors
+   * Fix Segfault on reload or quit for vloopback (maybe other v4l1 devices too)
+     http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2009x06x17x090603
+   * Fix warning for __USE_GNU redefined
+     http://www.lavrsen.dk/foswiki/bin/view/Motion/BugReport2009x06x17x122137
 
 Wesley Hosking
    * For pointing me to the absence of a frame length check using
@@ -1376,6 +1385,9 @@
 Robert Eugene Wood
    * Inverse pixels for locate box.
 
+Andreas Wrede
+  * Allow compile with NetBSD and make LP64 compliant video_freebsd.c 
+
 Damian Wrobel
    * Fix a segfault adding correct size to be used for bayer2rgb24(). 
      http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2007x03x30x175913
Index: video_common.c
===================================================================
--- video_common.c	(revisión: 452)
+++ video_common.c	(copia de trabajo)
@@ -597,8 +597,7 @@
         } else {
 #endif
             close(dev->fd);
-            munmap(viddevs->v4l_buffers[0], viddevs->size_map);
-            munmap(viddevs->v4l_buffers[1], viddevs->size_map);
+            munmap(viddevs->v4l_buffers[0], dev->size_map);
 #ifdef MOTION_V4L2
         }
 #endif
