malloc calls and ioctl calls to soundcard cause segfault

Shawn Webb shawnwebb at softhome.net
Wed Oct 13 13:15:15 PDT 2004


I've got to rewrite the source due to hard disk problems, so I'll just put
it in this email:

/* dsp_seg.c */
/* If there are any compile errors, forgive me; I'm not on a FreeBSD box */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/types.h>
#include <sys/soundcard.h>
#include <fcntl.h>

#define FORMAT AFMT_S16_LE
#define RATE 8000
#define CHANNELS 1

char *buf;
int fd;
int buflen;

void this_segfaults(void);

int main(void)
{
    fd = open("/dev/dsp", O_RDWR);
    if (fd < 0)
    {
        perror("open");
        exit(1);
    }

    this_segfaults();

    printf("m00\n");
    exit(0);
}

void this_segfaults(void)
{
    int arg;

    arg = FORMAT;
    if (ioctl(fd, SNDCTL_DSP_SETFMT, &arg) < 0)
    {
        perror("ioctl setfmt");
        exit(1);
    }

    if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &arg) < 0)
    {
        perror("ioctl getospace");
        exit(1);
    }

    printf("arg: %d\n", arg);

    buf = malloc(arg);
    if (!buf)
    {
        perror("malloc");
        exit(1);
    }

    arg = CHANNELS;
    if (ioctl(fd, SNDCTL_DSP_CHANNELS, &arg) < 0)
    {
        perror("ioctl channels");
        exit(1);
    }

    arg = RATE;
    if (ioctl(fd, SNDCTL_DSP_SETRATE, &arg) < 0)
    {
        perror("ioctl setrate");
        exit(1);
    }
}
/* End of source */

----- Original Message ----- 
From: "Robert Watson" <rwatson at freebsd.org>
To: "Shawn Webb" <shawnwebb at softhome.net>
Cc: <freebsd-hackers at freebsd.org>
Sent: Wednesday, October 13, 2004 1:47 AM
Subject: Re: malloc calls and ioctl calls to soundcard cause segfault


>
> On Tue, 12 Oct 2004, Shawn Webb wrote:
>
> > (attached is the source code to the segfaulting application)
>
> Doesn't appear to be -- if it was a large attachment, maybe the mailing
> list stripped it.  Could you give a URL for the source?
>
> Robert N M Watson             FreeBSD Core Team, TrustedBSD Projects
> robert at fledge.watson.org      Principal Research Scientist, McAfee
Research
>
>
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"



More information about the freebsd-hackers mailing list