summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-09-30 20:19:44 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-09-30 20:19:44 -0700
commitedca92c10572b6bb7dd60db156f545d98373f803 (patch)
tree0f22fb5c4203c48c2a8d7f6a71692f9b689d791d
parent93812aa7950342c809a9dcbd9d50379c050b51ac (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.c4
-rw-r--r--common.c30
-rw-r--r--decode11.c4
-rw-r--r--extensions.c14
-rw-r--r--fd.c5
-rw-r--r--proto.h2
-rw-r--r--scope.c2
-rw-r--r--server.c10
-rw-r--r--table11.c10
9 files changed, 33 insertions, 48 deletions
diff --git a/audio.c b/audio.c
index aaef19e..d7258f7 100644
--- a/audio.c
+++ b/audio.c
@@ -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
diff --git a/common.c b/common.c
index bf64beb..1baf288 100644
--- a/common.c
+++ b/common.c
@@ -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)
diff --git a/decode11.c b/decode11.c
index a9360ff..a23fa30 100644
--- a/decode11.c
+++ b/decode11.c
@@ -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;
diff --git a/fd.c b/fd.c
index 5096e70..395bbbb 100644
--- a/fd.c
+++ b/fd.c
@@ -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)));
diff --git a/proto.h b/proto.h
index d7dfaec..7963e86 100644
--- a/proto.h
+++ b/proto.h
@@ -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));
diff --git a/scope.c b/scope.c
index dfe9f00..f85cdba 100644
--- a/scope.c
+++ b/scope.c
@@ -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':
diff --git a/server.c b/server.c
index e9c1d9e..0943eec 100644
--- a/server.c
+++ b/server.c
@@ -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
diff --git a/table11.c b/table11.c
index 02dc5fb..56658b2 100644
--- a/table11.c
+++ b/table11.c
@@ -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;