]> code.delx.au - pulseaudio/blobdiff - src/pulse/mainloop-signal.c
core: Fix uninit pointer read in protocol-native
[pulseaudio] / src / pulse / mainloop-signal.c
index 9161dec46843dc6819e3e6573854c4de395cf304..89aafcbfc9f6c5bb7a3600139deeeebe72e3dbdf 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
 
 #ifdef HAVE_WINDOWS_H
 #include <windows.h>
 #endif
 
 #include <pulse/xmalloc.h>
-#include <pulse/gccmacro.h>
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/core-util.h>
+#include <pulsecore/i18n.h>
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
 
@@ -73,7 +72,8 @@ static void signal_handler(int sig) {
     signal(sig, signal_handler);
 #endif
 
-    pa_write(signal_pipe[1], &sig, sizeof(sig), NULL);
+    /* XXX: If writing fails, there's nothing we can do? */
+    (void) pa_write(signal_pipe[1], &sig, sizeof(sig), NULL);
 
     errno = saved_errno;
 }
@@ -89,7 +89,7 @@ static void dispatch(pa_mainloop_api*a, int sig) {
         }
 }
 
-static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, PA_GCC_UNUSED void *userdata) {
+static void callback(pa_mainloop_api*a, pa_io_event*e, int fd, pa_io_event_flags_t f, void *userdata) {
     ssize_t r;
     int sig;
 
@@ -123,15 +123,13 @@ int pa_signal_init(pa_mainloop_api *a) {
     pa_assert(signal_pipe[1] == -1);
     pa_assert(!io_event);
 
-    if (pipe(signal_pipe) < 0) {
+    if (pa_pipe_cloexec(signal_pipe) < 0) {
         pa_log("pipe(): %s", pa_cstrerror(errno));
         return -1;
     }
 
     pa_make_fd_nonblock(signal_pipe[0]);
     pa_make_fd_nonblock(signal_pipe[1]);
-    pa_make_fd_cloexec(signal_pipe[0]);
-    pa_make_fd_cloexec(signal_pipe[1]);
 
     api = a;
 
@@ -165,9 +163,11 @@ pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t _callback, void *userdata
     pa_assert(sig > 0);
     pa_assert(_callback);
 
+    pa_init_i18n();
+
     for (e = signals; e; e = e->next)
         if (e->sig == sig)
-            goto fail;
+            return NULL;
 
     e = pa_xnew(pa_signal_event, 1);
     e->sig = sig;
@@ -193,8 +193,7 @@ pa_signal_event* pa_signal_new(int sig, pa_signal_cb_t _callback, void *userdata
 
     return e;
 fail:
-    if (e)
-        pa_xfree(e);
+    pa_xfree(e);
     return NULL;
 }