[PATCH:xscope 02/14] Stop wrapping malloc & free
Alan Coopersmith
alan.coopersmith at ORACLE.COM
Sat Sep 24 08:48:20 PDT 2011
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
audio.c | 4 ++--
common.c | 30 +++---------------------------
decode11.c | 4 +++-
extensions.c | 14 ++++++++++----
fd.c | 5 ++---
proto.h | 2 --
scope.c | 2 +-
server.c | 10 ++++++----
table11.c | 10 ++++++----
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;
--
1.7.3.2
More information about the xorg-devel
mailing list