diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-09-30 20:19:44 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-09-30 20:19:44 -0700 |
commit | edca92c10572b6bb7dd60db156f545d98373f803 (patch) | |
tree | 0f22fb5c4203c48c2a8d7f6a71692f9b689d791d | |
parent | 93812aa7950342c809a9dcbd9d50379c050b51ac (diff) |
Stop wrapping malloc & free
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
-rw-r--r-- | audio.c | 4 | ||||
-rw-r--r-- | common.c | 30 | ||||
-rw-r--r-- | decode11.c | 4 | ||||
-rw-r--r-- | extensions.c | 14 | ||||
-rw-r--r-- | fd.c | 5 | ||||
-rw-r--r-- | proto.h | 2 | ||||
-rw-r--r-- | scope.c | 2 | ||||
-rw-r--r-- | server.c | 10 | ||||
-rw-r--r-- | table11.c | 10 |
9 files changed, 33 insertions, 48 deletions
@@ -107,7 +107,7 @@ StopAudioClientConnection( /* when a new connection is stopped, discard the old buffer */ if (CS[fd].SizeofSavedBytes > 0) - Free((char*)CS[fd].SavedBytes); + free(CS[fd].SavedBytes); } static long @@ -217,7 +217,7 @@ StopAudioServerConnection( /* when a new connection is stopped, discard the old buffer */ if (CS[fd].SizeofSavedBytes > 0) - Free((char *)CS[fd].SavedBytes); + free(CS[fd].SavedBytes); } static long @@ -76,32 +76,6 @@ panic (char *s) exit(1); } -/* ********************************************** */ -/* */ -/* Debugging forms of memory management */ -/* */ -/* ********************************************** */ - -void * -Malloc (long n) -{ - void *p; - p = malloc(n); - debug(64,(stderr, "%lx = malloc(%ld)\n", (unsigned long) p, n)); - if (p == NULL) - panic("no more malloc space"); - return(p); -} - -void -Free(void *p) -{ - debug(64,(stderr, "%lx = free\n", (unsigned long) p)); - free(p); -} - - - /* ************************************************************ */ /* */ /* Signal Handling support */ @@ -288,7 +262,9 @@ SetUpConnectionSocket( struct hostent *hp; (void) gethostname(MyHostName, sizeof(MyHostName)); - ScopeHost = (char *) Malloc((long)(1+strlen(MyHostName))); + ScopeHost = malloc((1+strlen(MyHostName))); + if (ScopeHost == NULL) + panic("Can't allocate memory for hostname"); strcpy(ScopeHost, MyHostName); hp = gethostbyname(MyHostName); if (hp == NULL) @@ -107,7 +107,9 @@ NewQEntry ( if (FreeQEntries == NULL) { /* create new queue entry */ - p = (struct QueueEntry *) Malloc ((long)(sizeof (*p))); + p = malloc (sizeof (*p)); + if (p == NULL) + panic("unable to allocate new QueueEntry"); } else { diff --git a/extensions.c b/extensions.c index b120b3e..cf5421f 100644 --- a/extensions.c +++ b/extensions.c @@ -87,7 +87,9 @@ DefineExtNameValue(int type, unsigned char value, const char *extname) panic("Impossible argument to DefineExtNameValue"); } namelen += strlen(typename); - exttypename = Malloc(namelen); + exttypename = malloc(namelen); + if (exttypename == NULL) + panic("Can't allocate memory for ExtNameValue"); snprintf(exttypename, namelen, "%s%s", extname, typename); DefineEValue(&TD[type], (unsigned long) value, exttypename); } @@ -96,22 +98,26 @@ void ProcessQueryExtensionRequest(long seq, const unsigned char *buf) { int namelen = IShort(&buf[4]); - char *extname = Malloc(namelen + 1); + char *extname = malloc(namelen + 1); struct extension_info *qe; + if (extname == NULL) + panic("Can't allocate memory for ExtensionRequest name"); memcpy(extname, &buf[8], namelen); extname[namelen] = '\0'; for (qe = query_list; qe != NULL; qe = qe->next) { if (strcmp(extname, qe->name) == 0) { /* already in list, no need to add */ - Free(extname); + free(extname); return; } } /* add to list */ - qe = Malloc(sizeof(struct extension_info)); + qe = malloc(sizeof(struct extension_info)); + if (qe == NULL) + panic("Can't allocate memory for extension_info"); qe->name = extname; qe->request = 0; qe->event = 0; @@ -105,10 +105,9 @@ InitializeFD(void) } /* allocate space for a File Descriptor (FD) Table */ - FDD = (struct FDDescriptor *) - Malloc ((long)(MaxFD * sizeof (struct FDDescriptor))); + FDD = malloc (MaxFD * sizeof (struct FDDescriptor)); if (FDD == NULL) { - panic("Can't allocate memory!"); + panic("Can't allocate memory for file descriptor table"); } bzero(FDD, (MaxFD * sizeof (struct FDDescriptor))); @@ -4,8 +4,6 @@ extern void enterprocedure (char *s); extern void warn (char *s); extern void panic (char *s); -extern void *Malloc (long n); -extern void Free (void *p); extern void SetSignalHandling (void); extern void SetUpConnectionSocket (int iport, void (*connectionFunc) (int)); @@ -748,7 +748,7 @@ ScanArgs ( 4 - I/O, connections 8 - Scope internals 16 - Message protocol - 32 - 64 - malloc + 32 - 64 - was malloc, now unused 128 - 256 - really low level */ case 'D': @@ -212,11 +212,13 @@ SaveBytes ( { /* not enough room so far; malloc more space and copy */ long SizeofNewBytes = (CS[fd].NumberofSavedBytes + n + 1); - unsigned char *NewBytes = (unsigned char *)Malloc (SizeofNewBytes); + unsigned char *NewBytes = malloc (SizeofNewBytes); + if (NewBytes == NULL) + panic("Can't allocate memory for SavedBytes"); bcopy(/* from */(char *)CS[fd].SavedBytes, /* to */(char *)NewBytes, /* count */(int)CS[fd].SizeofSavedBytes); - Free((char *)CS[fd].SavedBytes); + free(CS[fd].SavedBytes); CS[fd].SavedBytes = NewBytes; CS[fd].SizeofSavedBytes = SizeofNewBytes; } @@ -471,7 +473,7 @@ StopClientConnection ( /* when a new connection is stopped, discard the old buffer */ if (CS[fd].SizeofSavedBytes > 0) - Free((char*)CS[fd].SavedBytes); + free(CS[fd].SavedBytes); } long @@ -622,7 +624,7 @@ StopServerConnection ( /* when a new connection is stopped, discard the old buffer */ if (CS[fd].SizeofSavedBytes > 0) - Free((char *)CS[fd].SavedBytes); + free(CS[fd].SavedBytes); } long @@ -248,8 +248,9 @@ DefineEValue( struct ValueListEntry *p; /* define the new value */ - p = (struct ValueListEntry *) - Malloc ((long)(sizeof (struct ValueListEntry))); + p = malloc (sizeof (struct ValueListEntry)); + if (p == NULL) + panic("Can't allocate memory for Enum ValueListEntry"); p->Name = name; p->Value = value; @@ -303,8 +304,9 @@ DefineValues(TYPE type, long value, short length, short ctype, { struct ValueListEntry *p; - p = (struct ValueListEntry *) - Malloc ((long)(sizeof (struct ValueListEntry))); + p = malloc (sizeof (struct ValueListEntry)); + if (p == NULL) + panic("Can't allocate memory for ValueListEntry"); p->Name = name; p->Type = ctype; p->Length = length; |