[geeks] OS X malloc weirdness

Matthew Braun geeks at leydenjar.com
Mon Aug 23 14:28:56 CDT 2004


Ok, I'm stumped and I was wondering if anyone might have some insight:

I'm writing a little client app (yes, it's for a class) and I'm getting 
this when I run it:

admin at admins-Computer:build> ./mlpr
*** malloc: vm_allocate(size=131072) failed (error code=268435465)
*** malloc[623]: error: Can't allocate region
623
Connecting to host '127.0.0.1'
<snip>

Strangely, the error manifests when I print to stdout (code below). 
When I output to stderr, no problem, but when I use printf or fprintf 
to stdout, I get the malloc error (I'm not actually threading in this 
chunk of code; it's just for interoperability, so I can use printf). 
What the heck?



#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <unistd.h>
#include "socklib.h"

#define        oops(msg)       { perror(msg); exit(1); }

pthread_t emptyMutex;

pthread_mutex_t stdlib_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_t stdlib_mutex_holder = NULL; /* Needed to support recursive 
mutex operations under OS X */


int main(int ac, char *av[])
{
	/*sleep(3);*/
	int sock_id;
	int port;
	int mypid;
	char message[BUFSIZ];             /* to receive message */
	int messlen;                     /* for message length */

	emptyMutex = pthread_self();
	emptyMutex->sig = -1;
	stdlib_mutex_holder = emptyMutex;
	mypid = getpid();

	fprintf (stdout, "%d\n", mypid);
  	<snip>



More information about the geeks mailing list