Merged revisions 80166 via svnmerge from
[asterisk/asterisk.git] / utils / muted.c
index 73eadfa..6a32b6d 100644 (file)
  *
  */
 
-#ifndef __Darwin__
-#include <linux/soundcard.h>
-#else
+#ifdef __Darwin__
 #include <CoreAudio/AudioHardware.h> 
+#elif defined(__linux__) || defined(__FreeBSD__)
+#include <sys/soundcard.h>
 #endif
 #include <stdio.h>
 #include <errno.h>
@@ -85,8 +85,15 @@ static void add_channel(char *tech, char *location)
        chan = malloc(sizeof(struct channel));
        if (chan) {
                memset(chan, 0, sizeof(struct channel));
-               chan->tech = strdup(tech);
-               chan->location = strdup(location);
+               if (!(chan->tech = strdup(tech))) {
+                       free(chan);
+                       return;
+               }
+               if (!(chan->location = strdup(location))) {
+                       free(chan->tech);
+                       free(chan);
+                       return;
+               }
                chan->next = channels;
                channels = chan;
        }
@@ -223,7 +230,7 @@ static int connect_asterisk(void)
        sin.sin_family = AF_INET;
        sin.sin_port = htons(port);
        memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
-       if (connect(sock, &sin, sizeof(sin))) {
+       if (connect(sock, (struct sockaddr *)&sin, sizeof(sin))) {
                fprintf(stderr, "Failed to connect to '%s' port '%d': %s\n", host, port, strerror(errno));
                close(sock);
                return -1;
@@ -550,7 +557,10 @@ static void append_sub(struct channel *chan, char *name)
        sub = malloc(sizeof(struct subchannel));
        if (sub) {
                memset(sub, 0, sizeof(struct subchannel));
-               sub->name = strdup(name);
+               if (!(sub->name = strdup(name))) {
+                       free(sub);
+                       return;
+               }
                sub->next = chan->subs;
                chan->subs = sub;
        }