aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/os
diff options
context:
space:
mode:
authorMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-07-02 14:11:38 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2016-07-02 14:11:38 +0200
commit1dbd3c888a3eee51db5303bd93e95b84999f5d31 (patch)
tree84db92271726b42b8c0864c8b7c77b2330566fc1 /nx-X11/programs/Xserver/os
parent279d37127db241a9ee685f6b671f51aa21a972ea (diff)
parente85808245810d0cc6918104deef25213d5f9e06c (diff)
downloadnx-libs-1dbd3c888a3eee51db5303bd93e95b84999f5d31.tar.gz
nx-libs-1dbd3c888a3eee51db5303bd93e95b84999f5d31.tar.bz2
nx-libs-1dbd3c888a3eee51db5303bd93e95b84999f5d31.zip
Merge branch 'sunweaver-pr/backport-Xorg-memory-handling' into 3.6.x
Attributes GH PR #159: https://github.com/ArcticaProject/nx-libs/pull/159 Reviewed by: Vadim Troshchinskiy <vadim@qindel.com> -- Fri, 01 Jul 2016 12:47:46 -0700
Diffstat (limited to 'nx-X11/programs/Xserver/os')
-rw-r--r--nx-X11/programs/Xserver/os/Imakefile17
-rw-r--r--nx-X11/programs/Xserver/os/WaitFor.c6
-rw-r--r--nx-X11/programs/Xserver/os/access.c26
-rw-r--r--nx-X11/programs/Xserver/os/connection.c16
-rw-r--r--nx-X11/programs/Xserver/os/io.c48
-rw-r--r--nx-X11/programs/Xserver/os/log.c6
-rw-r--r--nx-X11/programs/Xserver/os/mitauth.c14
-rw-r--r--nx-X11/programs/Xserver/os/oscolor.c8
-rw-r--r--nx-X11/programs/Xserver/os/rpcauth.c6
-rw-r--r--nx-X11/programs/Xserver/os/utils.c177
-rw-r--r--nx-X11/programs/Xserver/os/xalloc.c817
-rw-r--r--nx-X11/programs/Xserver/os/xdmauth.c40
-rw-r--r--nx-X11/programs/Xserver/os/xdmcp.c14
-rw-r--r--nx-X11/programs/Xserver/os/xprintf.c4
14 files changed, 124 insertions, 1075 deletions
diff --git a/nx-X11/programs/Xserver/os/Imakefile b/nx-X11/programs/Xserver/os/Imakefile
index 00d28deb1..802725306 100644
--- a/nx-X11/programs/Xserver/os/Imakefile
+++ b/nx-X11/programs/Xserver/os/Imakefile
@@ -91,11 +91,6 @@ COLOR_SRCS=oscolor.c
COLOR_OBJS=oscolor.o
#endif
-#if UseInternalMalloc
-MALLOC_SRCS=xalloc.c
-MALLOC_OBJS=xalloc.o
-#endif
-
#if !HasSnprintf
SNPRINTF_SRCS = snprintf.c
SNPRINTF_OBJS = snprintf.o
@@ -119,19 +114,13 @@ BOOTSTRAPCFLAGS =
osinit.c utils.c log.c auth.c mitauth.c secauth.c \
$(XDMAUTHSRCS) $(RPCSRCS) xdmcp.c OtherSources \
transport.c $(SNPRINTF_SRCS) $(STRLCAT_SRCS) \
- $(MALLOC_SRCS) xprintf.c
+ xprintf.c
OBJS = WaitFor.o access.o connection.o io.o $(COLOR_OBJS) \
osinit.o utils.o log.o auth.o mitauth.o secauth.o \
$(XDMAUTHOBJS) $(RPCOBJS) xdmcp.o OtherObjects \
transport.o $(SNPRINTF_OBJS) $(STRLCAT_OBJS) \
- $(MALLOC_OBJS) xprintf.o
+ xprintf.o
-#if SpecialMalloc
- MEM_DEFINES = -DSPECIAL_MALLOC
-#endif /* SpecialMalloc */
-#if UseInternalMalloc
- MEM_DEFINES = -DINTERNAL_MALLOC
-#endif
#if UseMemLeak
MEM_DEFINES = -DMEMBUG
#endif
@@ -141,7 +130,6 @@ BOOTSTRAPCFLAGS =
DBM_DEFINES = NdbmDefines
ADM_DEFINES = -DADMPATH=\"$(ADMDIR)/X\%smsgs\"
XDMCP_DEFINES = ServerXdmcpDefines
- XALLOC_DEFINES = XallocDefines
ERROR_DEFINES = ServerErrorDefines
#if HasPam && HasPamMisc
PAM_DEFINES = -DUSE_PAM
@@ -189,7 +177,6 @@ SpecialCObjectRule(osinit,$(ICONFIGFILES),$(ADM_DEFINES))
SpecialCObjectRule(WaitFor,$(ICONFIGFILES),$(EXT_DEFINES))
SpecialCObjectRule(io,$(ICONFIGFILES),$(EXT_DEFINES))
SpecialCObjectRule(utils,$(ICONFIGFILES),$(XDMCP_DEFINES) $(EXT_DEFINES) $(ERROR_DEFINES) $(PAM_DEFINES))
-SpecialCObjectRule(xalloc,$(ICONFIGFILES),$(XALLOC_DEFINES))
#if defined(SparcArchitecture) && HasGcc && !HasGcc2
oscolor.o: oscolor.c $(ICONFIGFILES)
$(RM) $@
diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c
index 0a18c28c8..0f23c9d4a 100644
--- a/nx-X11/programs/Xserver/os/WaitFor.c
+++ b/nx-X11/programs/Xserver/os/WaitFor.c
@@ -650,7 +650,7 @@ TimerSet(OsTimerPtr timer, int flags, CARD32 millis,
if (!timer)
{
- timer = (OsTimerPtr)xalloc(sizeof(struct _OsTimerRec));
+ timer = (OsTimerPtr)malloc(sizeof(struct _OsTimerRec));
if (!timer)
return NULL;
}
@@ -730,7 +730,7 @@ TimerFree(OsTimerPtr timer)
if (!timer)
return;
TimerCancel(timer);
- xfree(timer);
+ free(timer);
}
void
@@ -750,7 +750,7 @@ TimerInit(void)
while ((timer = timers))
{
timers = timer->next;
- xfree(timer);
+ free(timer);
}
}
diff --git a/nx-X11/programs/Xserver/os/access.c b/nx-X11/programs/Xserver/os/access.c
index 7f45e5ec9..4090a9589 100644
--- a/nx-X11/programs/Xserver/os/access.c
+++ b/nx-X11/programs/Xserver/os/access.c
@@ -256,12 +256,12 @@ typedef struct _host {
int requested;
} HOST;
-#define MakeHost(h,l) (h)=(HOST *) xalloc(sizeof *(h)+(l));\
+#define MakeHost(h,l) (h)=(HOST *) malloc(sizeof *(h)+(l));\
if (h) { \
(h)->addr=(unsigned char *) ((h) + 1);\
(h)->requested = FALSE; \
}
-#define FreeHost(h) xfree(h)
+#define FreeHost(h) free(h)
static HOST *selfhosts = NULL;
static HOST *validhosts = NULL;
static int AccessEnabled = DEFAULT_ACCESS_CONTROL;
@@ -782,7 +782,7 @@ DefineSelf (int fd)
Error ("Getting interface count");
if (len < (ifn.lifn_count * sizeof(struct lifreq))) {
len = ifn.lifn_count * sizeof(struct lifreq);
- bufptr = xalloc(len);
+ bufptr = malloc(len);
}
#endif
@@ -1376,12 +1376,12 @@ Bool LocalClient(ClientPtr client)
&alen, (void **)&addr);
if (family == -1)
{
- xfree ((char *) from);
+ free ((char *) from);
return FALSE;
}
if (family == FamilyLocal)
{
- xfree ((char *) from);
+ free ((char *) from);
return TRUE;
}
for (host = selfhosts; host; host = host->next)
@@ -1389,7 +1389,7 @@ Bool LocalClient(ClientPtr client)
if (addrEqual (family, addr, alen, host))
return TRUE;
}
- xfree ((char *) from);
+ free ((char *) from);
}
return FALSE;
}
@@ -1477,7 +1477,7 @@ LocalClientCredAndGroups(ClientPtr client, int *pUid, int *pGid,
const gid_t *gids;
*nSuppGids = ucred_getgroups(peercred, &gids);
if (*nSuppGids > 0) {
- *pSuppGids = xalloc(sizeof(int) * (*nSuppGids));
+ *pSuppGids = malloc(sizeof(int) * (*nSuppGids));
if (*pSuppGids == NULL) {
*nSuppGids = 0;
} else {
@@ -1691,7 +1691,7 @@ GetHosts (
}
if (n)
{
- *data = ptr = (void *) xalloc (n);
+ *data = ptr = (void *) malloc (n);
if (!ptr)
{
return(BadAlloc);
@@ -1951,7 +1951,7 @@ siTypeAdd(const char *typeName, siAddrMatchFunc addrMatch,
}
}
- s = (struct siType *) xalloc(sizeof(struct siType));
+ s = (struct siType *) malloc(sizeof(struct siType));
if (s == NULL)
return BadAlloc;
@@ -2293,7 +2293,7 @@ static Bool
siLocalCredGetId(const char *addr, int len, siLocalCredPrivPtr lcPriv, int *id)
{
Bool parsedOK = FALSE;
- char *addrbuf = xalloc(len + 1);
+ char *addrbuf = malloc(len + 1);
if (addrbuf == NULL) {
return FALSE;
@@ -2327,7 +2327,7 @@ siLocalCredGetId(const char *addr, int len, siLocalCredPrivPtr lcPriv, int *id)
}
}
- xfree(addrbuf);
+ free(addrbuf);
return parsedOK;
}
@@ -2360,11 +2360,11 @@ siLocalCredAddrMatch(int family, void * addr, int len,
for (i = 0 ; i < connNumSuppGids; i++) {
if (connSuppGids[i] == siAddrId) {
- xfree(connSuppGids);
+ free(connSuppGids);
return TRUE;
}
}
- xfree(connSuppGids);
+ free(connSuppGids);
}
}
return FALSE;
diff --git a/nx-X11/programs/Xserver/os/connection.c b/nx-X11/programs/Xserver/os/connection.c
index 2df92bf91..15321458e 100644
--- a/nx-X11/programs/Xserver/os/connection.c
+++ b/nx-X11/programs/Xserver/os/connection.c
@@ -261,7 +261,7 @@ void SetConnectionTranslation(int conn, int client)
}
node = &((*node)->next);
}
- *node = (struct _ct_node*)xalloc(sizeof(struct _ct_node));
+ *node = (struct _ct_node*)malloc(sizeof(struct _ct_node));
(*node)->next = NULL;
(*node)->key = conn;
(*node)->value = client;
@@ -279,7 +279,7 @@ void ClearConnectionTranslation(void)
{
struct _ct_node *temp = node;
node = node->next;
- xfree(temp);
+ free(temp);
}
}
}
@@ -407,7 +407,7 @@ CreateWellKnownSockets(void)
}
else
{
- ListenTransFds = (int *) xalloc (ListenTransCount * sizeof (int));
+ ListenTransFds = (int *) malloc (ListenTransCount * sizeof (int));
for (i = 0; i < ListenTransCount; i++)
{
@@ -713,7 +713,7 @@ ClientAuthorized(ClientPtr client,
proto_n, auth_proto, auth_id);
}
- xfree ((char *) from);
+ free ((char *) from);
}
if (auth_id == (XID) ~0L) {
@@ -731,7 +731,7 @@ ClientAuthorized(ClientPtr client,
AuthAudit(client, TRUE, (struct sockaddr *) from, fromlen,
proto_n, auth_proto, auth_id);
- xfree ((char *) from);
+ free ((char *) from);
}
}
priv->auth_id = auth_id;
@@ -764,7 +764,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
#endif
)
return NullClient;
- oc = (OsCommPtr)xalloc(sizeof(OsCommRec));
+ oc = (OsCommPtr)malloc(sizeof(OsCommRec));
if (!oc)
return NullClient;
oc->trans_conn = trans_conn;
@@ -775,7 +775,7 @@ AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time)
oc->conn_time = conn_time;
if (!(client = NextAvailableClient((void *)oc)))
{
- xfree (oc);
+ free (oc);
return NullClient;
}
{
@@ -962,7 +962,7 @@ CloseDownFileDescriptor(OsCommPtr oc)
_XSERVTransClose(oc->trans_conn);
}
FreeOsBuffers(oc);
- xfree(oc);
+ free(oc);
#ifndef WIN32
ConnectionTranslation[connection] = 0;
#else
diff --git a/nx-X11/programs/Xserver/os/io.c b/nx-X11/programs/Xserver/os/io.c
index fefe3007f..d0862ddd4 100644
--- a/nx-X11/programs/Xserver/os/io.c
+++ b/nx-X11/programs/Xserver/os/io.c
@@ -222,8 +222,8 @@ ReadRequestFromClient(ClientPtr client)
register ConnectionInputPtr aci = AvailableInput->input;
if (aci->size > BUFWATERMARK)
{
- xfree(aci->buffer);
- xfree(aci);
+ free(aci->buffer);
+ free(aci);
}
else
{
@@ -321,7 +321,7 @@ ReadRequestFromClient(ClientPtr client)
/* make buffer bigger to accomodate request */
char *ibuf;
- ibuf = (char *)xrealloc(oci->buffer, needed);
+ ibuf = (char *)realloc(oci->buffer, needed);
if (!ibuf)
{
YieldControlDeath();
@@ -371,7 +371,7 @@ ReadRequestFromClient(ClientPtr client)
{
char *ibuf;
- ibuf = (char *)xrealloc(oci->buffer, BUFSIZE);
+ ibuf = (char *)realloc(oci->buffer, BUFSIZE);
if (ibuf)
{
oci->size = BUFSIZE;
@@ -504,8 +504,8 @@ InsertFakeRequest(ClientPtr client, char *data, int count)
ConnectionInputPtr aci = AvailableInput->input;
if (aci->size > BUFWATERMARK)
{
- xfree(aci->buffer);
- xfree(aci);
+ free(aci->buffer);
+ free(aci);
}
else
{
@@ -531,7 +531,7 @@ InsertFakeRequest(ClientPtr client, char *data, int count)
{
char *ibuf;
- ibuf = (char *)xrealloc(oci->buffer, gotnow + count);
+ ibuf = (char *)realloc(oci->buffer, gotnow + count);
if (!ibuf)
return(FALSE);
oci->size = gotnow + count;
@@ -1097,7 +1097,7 @@ FlushClient(ClientPtr who, OsCommPtr oc, char *extraBuf, int extraCount)
{
unsigned char *obuf;
- obuf = (unsigned char *)xrealloc(oco->buf,
+ obuf = (unsigned char *)realloc(oco->buf,
notWritten + BUFSIZE);
if (!obuf)
{
@@ -1154,8 +1154,8 @@ FlushClient(ClientPtr who, OsCommPtr oc, char *extraBuf, int extraCount)
}
if (oco->size > BUFWATERMARK)
{
- xfree(oco->buf);
- xfree(oco);
+ free(oco->buf);
+ free(oco);
}
else
{
@@ -1171,13 +1171,13 @@ AllocateInputBuffer(void)
{
ConnectionInputPtr oci;
- oci = (ConnectionInputPtr)xalloc(sizeof(ConnectionInput));
+ oci = (ConnectionInputPtr)malloc(sizeof(ConnectionInput));
if (!oci)
return (ConnectionInputPtr)NULL;
- oci->buffer = (char *)xalloc(BUFSIZE);
+ oci->buffer = (char *)malloc(BUFSIZE);
if (!oci->buffer)
{
- xfree(oci);
+ free(oci);
return (ConnectionInputPtr)NULL;
}
oci->size = BUFSIZE;
@@ -1192,13 +1192,13 @@ AllocateOutputBuffer(void)
{
ConnectionOutputPtr oco;
- oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput));
+ oco = (ConnectionOutputPtr)malloc(sizeof(ConnectionOutput));
if (!oco)
return (ConnectionOutputPtr)NULL;
- oco->buf = (unsigned char *) xalloc(BUFSIZE);
+ oco->buf = (unsigned char *) malloc(BUFSIZE);
if (!oco->buf)
{
- xfree(oco);
+ free(oco);
return (ConnectionOutputPtr)NULL;
}
oco->size = BUFSIZE;
@@ -1218,8 +1218,8 @@ FreeOsBuffers(OsCommPtr oc)
{
if (FreeInputs)
{
- xfree(oci->buffer);
- xfree(oci);
+ free(oci->buffer);
+ free(oci);
}
else
{
@@ -1234,8 +1234,8 @@ FreeOsBuffers(OsCommPtr oc)
{
if (FreeOutputs)
{
- xfree(oco->buf);
- xfree(oco);
+ free(oco->buf);
+ free(oco);
}
else
{
@@ -1255,13 +1255,13 @@ ResetOsBuffers(void)
while ((oci = FreeInputs))
{
FreeInputs = oci->next;
- xfree(oci->buffer);
- xfree(oci);
+ free(oci->buffer);
+ free(oci);
}
while ((oco = FreeOutputs))
{
FreeOutputs = oco->next;
- xfree(oco->buf);
- xfree(oco);
+ free(oco->buf);
+ free(oco);
}
}
diff --git a/nx-X11/programs/Xserver/os/log.c b/nx-X11/programs/Xserver/os/log.c
index 84381dbf2..d97317819 100644
--- a/nx-X11/programs/Xserver/os/log.c
+++ b/nx-X11/programs/Xserver/os/log.c
@@ -186,7 +186,7 @@ LogInit(const char *fname, const char *backup)
char *logFileName = NULL;
if (fname && *fname) {
- /* xalloc() can't be used yet. */
+ /* malloc() can't be used yet. */
logFileName = malloc(strlen(fname) + strlen(display) + 1);
if (!logFileName)
FatalError("Cannot allocate space for the log file name\n");
@@ -236,7 +236,7 @@ LogInit(const char *fname, const char *backup)
* needed.
*/
if (saveBuffer && bufferSize > 0) {
- free(saveBuffer); /* Must be free(), not xfree() */
+ free(saveBuffer); /* Must be free(), not free() */
saveBuffer = NULL;
bufferSize = 0;
}
@@ -333,7 +333,7 @@ LogVWrite(int verb, const char *f, va_list args)
} else if (needBuffer) {
/*
* Note, this code is used before OsInit() has been called, so
- * xalloc() and friends can't be used.
+ * malloc() and friends can't be used.
*/
if (len > bufferUnused) {
bufferSize += 1024;
diff --git a/nx-X11/programs/Xserver/os/mitauth.c b/nx-X11/programs/Xserver/os/mitauth.c
index abf7976af..2630a81ae 100644
--- a/nx-X11/programs/Xserver/os/mitauth.c
+++ b/nx-X11/programs/Xserver/os/mitauth.c
@@ -57,12 +57,12 @@ MitAddCookie (
{
struct auth *new;
- new = (struct auth *) xalloc (sizeof (struct auth));
+ new = (struct auth *) malloc (sizeof (struct auth));
if (!new)
return 0;
- new->data = (char *) xalloc ((unsigned) data_length);
+ new->data = (char *) malloc ((unsigned) data_length);
if (!new->data) {
- xfree(new);
+ free(new);
return 0;
}
new->next = mit_auth;
@@ -98,8 +98,8 @@ MitResetCookie (void)
for (auth = mit_auth; auth; auth=next) {
next = auth->next;
- xfree (auth->data);
- xfree (auth);
+ free (auth->data);
+ free (auth);
}
mit_auth = 0;
return 0;
@@ -154,8 +154,8 @@ MitRemoveCookie (
prev->next = auth->next;
else
mit_auth = auth->next;
- xfree (auth->data);
- xfree (auth);
+ free (auth->data);
+ free (auth);
return 1;
}
}
diff --git a/nx-X11/programs/Xserver/os/oscolor.c b/nx-X11/programs/Xserver/os/oscolor.c
index a8b01b4b9..2ea81060d 100644
--- a/nx-X11/programs/Xserver/os/oscolor.c
+++ b/nx-X11/programs/Xserver/os/oscolor.c
@@ -134,11 +134,11 @@ OsLookupColor(int screen, char *name, unsigned int len,
if(!rgb_dbm)
return(0);
- /* we use xalloc here so that we can compile with cc without alloca
+ /* we use malloc here so that we can compile with cc without alloca
* when otherwise using gcc */
if (len < sizeof(buf))
lowername = buf;
- else if (!(lowername = (char *)xalloc(len + 1)))
+ else if (!(lowername = (char *)malloc(len + 1)))
return(0);
CopyISOLatin1Lowered ((unsigned char *) lowername, (unsigned char *) name,
(int)len);
@@ -152,7 +152,7 @@ OsLookupColor(int screen, char *name, unsigned int len,
#endif
if (len >= sizeof(buf))
- xfree(lowername);
+ free(lowername);
if(dbent.dptr)
{
@@ -372,7 +372,7 @@ lookup(char *name, int len, Bool create)
else
prev = &(hashTab[h]);
- if (!entry && create && (entry = (dbEntryPtr)xalloc(sizeof(dbEntry) +len)))
+ if (!entry && create && (entry = (dbEntryPtr)malloc(sizeof(dbEntry) +len)))
{
*prev = entry;
entry->link = NULL;
diff --git a/nx-X11/programs/Xserver/os/rpcauth.c b/nx-X11/programs/Xserver/os/rpcauth.c
index 91823553c..40ea7ad97 100644
--- a/nx-X11/programs/Xserver/os/rpcauth.c
+++ b/nx-X11/programs/Xserver/os/rpcauth.c
@@ -77,7 +77,7 @@ authdes_ezdecode(char *inmsg, int len)
XDR xdr;
SVCXPRT xprt;
- temp_inmsg = (char *) xalloc(len);
+ temp_inmsg = (char *) malloc(len);
if (temp_inmsg == NULL) {
why = AUTH_FAILED; /* generic error, since there is no AUTH_BADALLOC */
return NULL;
@@ -94,7 +94,7 @@ authdes_ezdecode(char *inmsg, int len)
why = AUTH_FAILED;
xdrmem_create(&xdr, temp_inmsg, len, XDR_DECODE);
- if ((r.rq_clntcred = (caddr_t) xalloc(MAX_AUTH_BYTES)) == NULL)
+ if ((r.rq_clntcred = (caddr_t) malloc(MAX_AUTH_BYTES)) == NULL)
goto bad1;
r.rq_xprt = &xprt;
@@ -121,7 +121,7 @@ authdes_ezdecode(char *inmsg, int len)
return (((struct authdes_cred *) r.rq_clntcred)->adc_fullname.name);
bad2:
- xfree(r.rq_clntcred);
+ free(r.rq_clntcred);
bad1:
return ((char *)0); /* ((struct authdes_cred *) NULL); */
}
diff --git a/nx-X11/programs/Xserver/os/utils.c b/nx-X11/programs/Xserver/os/utils.c
index 90cf55d1a..f5f09c320 100644
--- a/nx-X11/programs/Xserver/os/utils.c
+++ b/nx-X11/programs/Xserver/os/utils.c
@@ -261,12 +261,6 @@ int SyncOn = 0;
extern int SelectWaitTime;
#endif
-#ifdef DEBUG
-#ifndef SPECIAL_MALLOC
-#define MEMBUG
-#endif
-#endif
-
#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
#define HAS_SAVED_IDS_AND_SETEUID
#endif
@@ -1186,7 +1180,7 @@ InsertFileIntoCommandLine(
fstat(fileno(f), &st);
- buf = (char *) xalloc((unsigned) st.st_size + 1);
+ buf = (char *) malloc((unsigned) st.st_size + 1);
if (!buf)
FatalError("Out of Memory\n");
@@ -1226,12 +1220,12 @@ InsertFileIntoCommandLine(
}
}
- buf = (char *) xrealloc(buf, q - buf);
+ buf = (char *) realloc(buf, q - buf);
if (!buf)
FatalError("Out of memory reallocing option buf\n");
*resargc = prefix_argc + insert_argc + suffix_argc;
- *resargv = (char **) xalloc((*resargc + 1) * sizeof(char *));
+ *resargv = (char **) malloc((*resargc + 1) * sizeof(char *));
if (!*resargv)
FatalError("Out of Memory\n");
@@ -1316,7 +1310,7 @@ set_font_authorizations(char **authorizations, int *authlen, void * client)
#endif
len = strlen(hnameptr) + 1;
- result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4);
+ result = malloc(len + sizeof(AUTHORIZATION_NAME) + 4);
p = result;
*p++ = sizeof(AUTHORIZATION_NAME) >> 8;
@@ -1342,80 +1336,20 @@ set_font_authorizations(char **authorizations, int *authlen, void * client)
#endif /* TCPCONN */
}
-/* XALLOC -- X's internal memory allocator. Why does it return unsigned
- * long * instead of the more common char *? Well, if you read K&R you'll
- * see they say that alloc must return a pointer "suitable for conversion"
- * to whatever type you really want. In a full-blown generic allocator
- * there's no way to solve the alignment problems without potentially
- * wasting lots of space. But we have a more limited problem. We know
- * we're only ever returning pointers to structures which will have to
- * be long word aligned. So we are making a stronger guarantee. It might
- * have made sense to make Xalloc return char * to conform with people's
- * expectations of malloc, but this makes lint happier.
- */
-
-#ifndef INTERNAL_MALLOC
-
-void *
-Xalloc(unsigned long amount)
-{
- register void * ptr;
-
- if ((long)amount <= 0) {
- return (unsigned long *)NULL;
- }
- /* aligned extra on long word boundary */
- amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
-#ifdef MEMBUG
- if (!Must_have_memory && Memory_fail &&
- ((random() % MEM_FAIL_SCALE) < Memory_fail))
- return (unsigned long *)NULL;
-#endif
- if ((ptr = (void *)malloc(amount))) {
- return (unsigned long *)ptr;
- }
- if (Must_have_memory)
- FatalError("Out of memory");
- return (unsigned long *)NULL;
-}
-
/*****************
* XNFalloc
- * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory
+ * "no failure" alloc
*****************/
void *
XNFalloc(unsigned long amount)
{
- register void * ptr;
-
- if ((long)amount <= 0)
- {
- return (unsigned long *)NULL;
- }
- /* aligned extra on long word boundary */
- amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
- ptr = (void *)malloc(amount);
+ void *ptr = malloc(amount);
if (!ptr)
{
FatalError("Out of memory");
}
- return ((unsigned long *)ptr);
-}
-
-/*****************
- * Xcalloc
- *****************/
-
-void *
-Xcalloc(unsigned long amount)
-{
- unsigned long *ret;
-
- ret = Xalloc (amount);
- if (ret)
- bzero ((char *) ret, (int) amount);
- return ret;
+ return ptr;
}
/*****************
@@ -1425,72 +1359,24 @@ Xcalloc(unsigned long amount)
void *
XNFcalloc(unsigned long amount)
{
- unsigned long *ret;
-
- ret = Xalloc (amount);
- if (ret)
- bzero ((char *) ret, (int) amount);
- else if ((long)amount > 0)
- FatalError("Out of memory");
+ void *ret = calloc(1, amount);
+ if (!ret)
+ FatalError("XNFcalloc: Out of memory");
return ret;
}
/*****************
- * Xrealloc
- *****************/
-
-void *
-Xrealloc(void * ptr, unsigned long amount)
-{
-#ifdef MEMBUG
- if (!Must_have_memory && Memory_fail &&
- ((random() % MEM_FAIL_SCALE) < Memory_fail))
- return (unsigned long *)NULL;
-#endif
- if ((long)amount <= 0)
- {
- if (ptr && !amount)
- free(ptr);
- return (unsigned long *)NULL;
- }
- amount = (amount + (sizeof(long) - 1)) & ~(sizeof(long) - 1);
- if (ptr)
- ptr = (void *)realloc((char *)ptr, amount);
- else
- ptr = (void *)malloc(amount);
- if (ptr)
- return (unsigned long *)ptr;
- if (Must_have_memory)
- FatalError("Out of memory");
- return (unsigned long *)NULL;
-}
-
-/*****************
* XNFrealloc
- * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory
+ * "no failure" realloc
*****************/
void *
XNFrealloc(void * ptr, unsigned long amount)
{
- if (( ptr = (void *)Xrealloc( ptr, amount ) ) == NULL)
- {
- if ((long)amount > 0)
- FatalError( "Out of memory" );
- }
- return ((unsigned long *)ptr);
-}
-
-/*****************
- * Xfree
- * calls free
- *****************/
-
-void
-Xfree(void * ptr)
-{
- if (ptr)
- free((char *)ptr);
+ void *ret = realloc(ptr, amount);
+ if (!ret)
+ FatalError("XNFrealloc: Out of memory");
+ return ret;
}
void
@@ -1506,35 +1392,28 @@ OsInitAllocator (void)
been_here = 1;
#endif
}
-#endif /* !INTERNAL_MALLOC */
-
char *
Xstrdup(const char *s)
{
- char *sd;
-
if (s == NULL)
return NULL;
-
- sd = (char *)Xalloc(strlen(s) + 1);
- if (sd != NULL)
- strcpy(sd, s);
- return sd;
+ return strdup(s);
}
char *
XNFstrdup(const char *s)
{
- char *sd;
+ char *ret;
if (s == NULL)
return NULL;
- sd = (char *)XNFalloc(strlen(s) + 1);
- strcpy(sd, s);
- return sd;
+ ret = strdup(s);
+ if (!ret)
+ FatalError("XNFstrdup: Out of memory");
+ return ret;
}
#ifdef SMART_SCHEDULE
@@ -1808,11 +1687,11 @@ Popen(char *command, char *type)
if ((*type != 'r' && *type != 'w') || type[1])
return NULL;
- if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL)
+ if ((cur = (struct pid *)malloc(sizeof(struct pid))) == NULL)
return NULL;
if (pipe(pdes) < 0) {
- xfree(cur);
+ free(cur);
return NULL;
}
@@ -1826,7 +1705,7 @@ Popen(char *command, char *type)
case -1: /* error */
close(pdes[0]);
close(pdes[1]);
- xfree(cur);
+ free(cur);
#ifdef NX_TRANS_EXIT
if (OsVendorEndRedirectErrorFProc != NULL) {
OsVendorEndRedirectErrorFProc();
@@ -1946,11 +1825,11 @@ Fopen(char *file, char *type)
if ((*type != 'r' && *type != 'w') || type[1])
return NULL;
- if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL)
+ if ((cur = (struct pid *)malloc(sizeof(struct pid))) == NULL)
return NULL;
if (pipe(pdes) < 0) {
- xfree(cur);
+ free(cur);
return NULL;
}
@@ -1958,7 +1837,7 @@ Fopen(char *file, char *type)
case -1: /* error */
close(pdes[0]);
close(pdes[1]);
- xfree(cur);
+ free(cur);
return NULL;
case 0: /* child */
if (setgid(getgid()) == -1)
@@ -2052,7 +1931,7 @@ Pclose(void * iop)
pidlist = cur->next;
else
last->next = cur->next;
- xfree(cur);
+ free(cur);
/* allow EINTR again */
OsReleaseSignals ();
diff --git a/nx-X11/programs/Xserver/os/xalloc.c b/nx-X11/programs/Xserver/os/xalloc.c
deleted file mode 100644
index 4d2d3f1ee..000000000
--- a/nx-X11/programs/Xserver/os/xalloc.c
+++ /dev/null
@@ -1,817 +0,0 @@
-#define FATALERRORS 1
-/*
-Copyright (C) 1995 Pascal Haible. All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the "Software"),
-to deal in the Software without restriction, including without limitation
-the rights to use, copy, modify, merge, publish, distribute, sublicense,
-and/or sell copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-PASCAL HAIBLE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
-OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-Except as contained in this notice, the name of Pascal Haible shall
-not be used in advertising or otherwise to promote the sale, use or other
-dealings in this Software without prior written authorization from
-Pascal Haible.
-*/
-
-/* $XFree86: xc/programs/Xserver/os/xalloc.c,v 3.35tsi Exp $ */
-
-/* Only used if INTERNAL_MALLOC is defined
- * - otherwise xalloc() in utils.c is used
- */
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifdef INTERNAL_MALLOC
-
-#include <stdlib.h> /* for malloc() etc. */
-
-#include <nx-X11/Xos.h>
-#include "misc.h"
-#include <nx-X11/X.h>
-
-#ifdef XALLOC_LOG
-#include <stdio.h>
-#endif
-
-extern Bool Must_have_memory;
-
-/*
- ***** New malloc approach for the X server *****
- * Pascal Haible 1995
- *
- * Some statistics about memory allocation of the X server
- * The test session included several clients of different size, including
- * xv, emacs and xpaint with a new canvas of 3000x2000, zoom 5.
- * All clients were running together.
- * A protocolling version of Xalloc recorded 318917 allocating actions
- * (191573 Xalloc, 85942 XNFalloc, 41438 Xrealloc, 279727 Xfree).
- * Results grouped by size, excluding the next lower size
- * (i.e. size=32 means 16<size<=32):
- *
- * size nr of alloc max nr of blocks allocated together
- * 8 1114 287
- * 16 17341 4104
- * 32 147352 2068
- * 64 59053 2518
- * 128 46882 1230
- * 256 20544 1217
- * 512 6808 117
- * 1024 8254 171
- * 2048 4841 287
- * 4096 2429 84
- * 8192 3364 85
- * 16384 573 22
- * 32768 49 7
- * 65536 45 5
- * 131072 48 2
- * 262144 209 2
- * 524288 7 4
- * 1048576 2 1
- * 8388608 2 2
- *
- * The most used sizes:
- * count size
- * 24 136267
- * 40 37055
- * 72 17278
- * 56 13504
- * 80 9372
- * 16 8966
- * 32 8411
- * 136 8399
- * 104 7690
- * 12 7630
- * 120 5512
- * 88 4634
- * 152 3062
- * 52 2881
- * 48 2736
- * 156 1569
- * 168 1487
- * 160 1483
- * 28 1446
- * 1608 1379
- * 184 1305
- * 552 1270
- * 64 934
- * 320 891
- * 8 754
- *
- * Conclusions: more than the half of all allocations are <= 32 bytes.
- * But of these about 150,000 blocks, only a maximum of about 6,000 are
- * allocated together (including memory leaks..).
- * On the other side, only 935 of the 191573 or 0.5% were larger than 8kB
- * (362 or 0.2% larger than 16k).
- *
- * What makes the server really grow is the fragmentation of the heap,
- * and the fact that it can't shrink.
- * To cure this, we do the following:
- * - large blocks (>=11k) are mmapped on xalloc, and unmapped on xfree,
- * so we don't need any free lists etc.
- * As this needs 2 system calls, we only do this for the quite
- * infrequent large (>=11k) blocks.
- * - instead of reinventing the wheel, we use system malloc for medium
- * sized blocks (>256, <11k).
- * - for small blocks (<=256) we use an other approach:
- * As we need many small blocks, and most ones for a short time,
- * we don't go through the system malloc:
- * for each fixed sizes a seperate list of free blocks is kept.
- * to KISS (Keep it Small and Simple), we don't free them
- * (not freeing a block of 32 bytes won't be worse than having fragmented
- * a larger area on allocation).
- * This way, we (almost) allways have a fitting free block right at hand,
- * and don't have to walk any lists.
- */
-
-/*
- * structure layout of a allocated block
- * unsigned long size:
- * rounded up netto size for small and medium blocks
- * brutto size == mmap'ed area for large blocks
- * unsigned long DEBUG ? MAGIC : unused
- * .... data
- * ( unsigned long MAGIC2 ) only if SIZE_TAIL defined
- *
- */
-
-/* use otherwise unused long in the header to store a magic */
-/* shouldn't this be removed for production release ? */
-#define XALLOC_DEBUG
-
-#ifdef XALLOC_DEBUG
-/* Xfree fills the memory with a certain pattern (currently 0xF0) */
-/* this should really be removed for production release! */
-#define XFREE_ERASES
-#endif
-
-/* this must be a multiple of SIZE_STEPS below */
-#define MAX_SMALL 264 /* quite many blocks of 264 */
-
-#define MIN_LARGE (11*1024)
-/* worst case is 25% loss with a page size of 4k */
-
-/* SIZE_STEPS defines the granularity of size of small blocks -
- * this makes blocks align to that, too! */
-#define SIZE_STEPS (sizeof(double))
-#define SIZE_HEADER (2*sizeof(long)) /* = sizeof(double) for 32bit */
-#ifdef XALLOC_DEBUG
-#if defined(__sparc__)
-#define SIZE_TAIL (2*sizeof(long)) /* = sizeof(double) for 32bit */
-#else
-#define SIZE_TAIL (sizeof(long))
-#endif
-#endif
-
-#undef TAIL_SIZE
-#ifdef SIZE_TAIL
-#define TAIL_SIZE SIZE_TAIL
-#else
-#define TAIL_SIZE 0
-#endif
-
-#if defined (_LP64) || \
- defined(__alpha__) || defined(__alpha) || \
- defined(__ia64__) || defined(ia64) || \
- defined(__sparc64__) || \
- defined(__s390x__) || \
- defined(__amd64__) || defined(amd64) || \
- defined(__powerpc64__) || \
- (defined(sgi) && _MIPS_SZLONG == 64))
-#define MAGIC 0x1404196414071968
-#define MAGIC_FREE 0x1506196615061966
-#define MAGIC2 0x2515207525182079
-#else
-#define MAGIC 0x14071968
-#define MAGIC_FREE 0x15061966
-#define MAGIC2 0x25182079
-#endif
-
-/* To get some statistics about memory allocation */
-
-#ifdef XALLOC_LOG
-#define XALLOC_LOG_FILE "/tmp/Xalloc.log" /* unsecure... */
-#define LOG_BODY(_body) \
- { FILE *f; \
- f = fopen(XALLOC_LOG_FILE, "a"); \
- if (NULL!=f) { \
- _body; \
- fclose(f); \
- } \
- }
-#if defined(linux) && defined(i386)
-#define LOG_ALLOC(_fun, _size, _ret) \
- { unsigned long *from; \
- __asm__("movl %%ebp,%0" : /*OUT*/ "=r" (from) : /*IN*/ ); \
- LOG_BODY(fprintf(f, "%s\t%i\t%p\t[%lu]\n", _fun, _size, _ret, *(from+1))) \
- }
-#else
-#define LOG_ALLOC(_fun, _size, _ret) \
- LOG_BODY(fprintf(f, "%s\t%i\t%p\n", _fun, _size, _ret))
-#endif
-#define LOG_REALLOC(_fun, _ptr, _size, _ret) \
- LOG_BODY(fprintf(f, "%s\t%p\t%i\t%p\n", _fun, _ptr, _size, _ret))
-#define LOG_FREE(_fun, _ptr) \
- LOG_BODY(fprintf(f, "%s\t%p\n", _fun, _ptr))
-#else
-#define LOG_ALLOC(_fun, _size, _ret)
-#define LOG_REALLOC(_fun, _ptr, _size, _ret)
-#define LOG_FREE(_fun, _ptr)
-#endif /* XALLOC_LOG */
-
-static unsigned long *free_lists[MAX_SMALL/SIZE_STEPS];
-
-/*
- * systems that support it should define HAS_MMAP_ANON or MMAP_DEV_ZERO
- * and include the appropriate header files for
- * mmap(), munmap(), PROT_READ, PROT_WRITE, MAP_PRIVATE,
- * PAGE_SIZE or _SC_PAGESIZE (and MAP_ANON for HAS_MMAP_ANON).
- *
- * systems that don't support MAP_ANON fall through to the 2 fold behaviour
- */
-
-#if defined(linux)
-#define HAS_MMAP_ANON
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <asm/page.h> /* PAGE_SIZE */
-#define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */
-#define HAS_GETPAGESIZE
-#endif /* linux */
-
-#if defined(__GNU__)
-#define HAS_MMAP_ANON
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <mach/vm_param.h> /* PAGE_SIZE */
-#define HAS_SC_PAGESIZE
-#define HAS_GETPAGESIZE
-#endif /* __GNU__ */
-
-#if defined(CSRG_BASED)
-#define HAS_MMAP_ANON
-#define HAS_GETPAGESIZE
-#include <sys/types.h>
-#include <sys/mman.h>
-#endif /* CSRG_BASED */
-
-#if defined(DGUX)
-#define HAS_GETPAGESIZE
-#define MMAP_DEV_ZERO
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#endif /* DGUX */
-
-#if defined(SVR4) && !defined(DGUX)
-#define MMAP_DEV_ZERO
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#endif /* SVR4 && !DGUX */
-
-#if defined(sun) && !defined(SVR4) /* SunOS */
-#define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */
-#define HAS_GETPAGESIZE
-#include <sys/types.h>
-#include <sys/mman.h>
-#endif /* sun && !SVR4 */
-
-#ifdef XNO_SYSCONF
-#undef _SC_PAGESIZE
-#endif
-
-#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO)
-static int pagesize;
-#endif
-
-#ifdef MMAP_DEV_ZERO
-static int devzerofd = -1;
-#include <errno.h>
-#endif
-
-/*
- * empty trap function for gdb. Breakpoint here
- * to find who tries to free a free area
- */
-void XfreeTrap(void)
-{
-}
-
-void *
-Xalloc (unsigned long amount)
-{
- register unsigned long *ptr;
- int indx;
-
- /* sanity checks */
-
- /* zero size requested */
- if (amount == 0) {
- LOG_ALLOC("Xalloc=0", amount, 0);
- return NULL;
- }
- /* negative size (or size > 2GB) - what do we do? */
- if ((long)amount < 0) {
- /* Diagnostic */
-#ifdef FATALERRORS
- FatalError("Xalloc: Xalloc(<0)\n");
-#else
- ErrorF("Xalloc warning: Xalloc(<0) ignored..\n");
-#endif
- LOG_ALLOC("Xalloc<0", amount, 0);
- return NULL;
- }
-
- /* alignment check */
-#if defined(__alpha__) || defined(__alpha) || \
- defined(__sparc__) || \
- defined(__mips__) || \
- defined(__powerpc__) || \
- defined(__arm32__) || \
- defined(__ia64__) || defined(ia64) || \
- defined(__s390x__) || defined(__s390__)
- amount = (amount + (sizeof(long)-1)) & ~(sizeof(long)-1);
-#endif
-
- if (amount <= MAX_SMALL) {
- /*
- * small block
- */
- /* pick a ready to use small chunk */
- indx = (amount-1) / SIZE_STEPS;
- ptr = free_lists[indx];
- if (NULL == ptr) {
- /* list empty - get 20 or 40 more */
- /* amount = size rounded up */
- amount = (indx+1) * SIZE_STEPS;
- ptr = (unsigned long *)calloc(1,(amount+SIZE_HEADER+TAIL_SIZE)
- * (amount<100 ? 40 : 20));
- if (NULL!=ptr) {
- int i;
- unsigned long *p1, *p2;
- p1 = 0;
- p2 = (unsigned long *)((char *)ptr + SIZE_HEADER);
- for (i=0; i<(amount<100 ? 40 : 20); i++) {
- p1 = p2;
- p1[-2] = amount;
-#ifdef XALLOC_DEBUG
- p1[-1] = MAGIC_FREE;
-#endif /* XALLOC_DEBUG */
-#ifdef SIZE_TAIL
- *(unsigned long *)((unsigned char *)p1 + amount) = MAGIC2;
-#endif /* SIZE_TAIL */
- p2 = (unsigned long *)((char *)p1 + SIZE_HEADER + amount + TAIL_SIZE);
- *(unsigned long **)p1 = p2;
- }
- /* last one has no next one */
- *(unsigned long **)p1 = NULL;
- /* put the second in the list */
- free_lists[indx] = (unsigned long *)((char *)ptr + SIZE_HEADER + amount + TAIL_SIZE + SIZE_HEADER);
- /* take the fist one */
- ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
- LOG_ALLOC("Xalloc-S", amount, ptr);
- ptr[-1] = MAGIC;
- return (void *)ptr;
- } /* else fall through to 'Out of memory' */
- } else {
- /* take that piece of mem out of the list */
- free_lists[indx] = *((unsigned long **)ptr);
- /* already has size (and evtl. magic) filled in */
-#ifdef XALLOC_DEBUG
- ptr[-1] = MAGIC;
-#endif /* XALLOC_DEBUG */
- LOG_ALLOC("Xalloc-S", amount, ptr);
- return (void *)ptr;
- }
-
-#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
- } else if (amount >= MIN_LARGE) {
- /*
- * large block
- */
- /* mmapped malloc */
- /* round up amount */
- amount += SIZE_HEADER + TAIL_SIZE;
- /* round up brutto amount to a multiple of the page size */
- amount = (amount + pagesize-1) & ~(pagesize-1);
-#ifdef MMAP_DEV_ZERO
- ptr = (unsigned long *)mmap((caddr_t)0,
- (size_t)amount,
- PROT_READ | PROT_WRITE,
- MAP_PRIVATE,
- devzerofd,
- (off_t)0);
-#else
- ptr = (unsigned long *)mmap((caddr_t)0,
- (size_t)amount,
- PROT_READ | PROT_WRITE,
- MAP_ANON | MAP_PRIVATE,
- -1,
- (off_t)0);
-#endif
- if (-1!=(long)ptr) {
- ptr[0] = amount - SIZE_HEADER - TAIL_SIZE;
-#ifdef XALLOC_DEBUG
- ptr[1] = MAGIC;
-#endif /* XALLOC_DEBUG */
-#ifdef SIZE_TAIL
- ((unsigned long *)((char *)ptr + amount - TAIL_SIZE))[0] = MAGIC2;
-#endif /* SIZE_TAIL */
- ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
- LOG_ALLOC("Xalloc-L", amount, ptr);
- return (void *)ptr;
- } /* else fall through to 'Out of memory' */
-#endif /* HAS_MMAP_ANON || MMAP_DEV_ZERO */
- } else {
- /*
- * medium sized block
- */
- /* 'normal' malloc() */
- ptr=(unsigned long *)calloc(1,amount+SIZE_HEADER+TAIL_SIZE);
- if (ptr != (unsigned long *)NULL) {
- ptr[0] = amount;
-#ifdef XALLOC_DEBUG
- ptr[1] = MAGIC;
-#endif /* XALLOC_DEBUG */
-#ifdef SIZE_TAIL
- *(unsigned long *)((char *)ptr + amount + SIZE_HEADER) = MAGIC2;
-#endif /* SIZE_TAIL */
- ptr = (unsigned long *)((char *)ptr + SIZE_HEADER);
- LOG_ALLOC("Xalloc-M", amount, ptr);
- return (void *)ptr;
- }
- }
- if (Must_have_memory)
- FatalError("Out of memory");
- LOG_ALLOC("Xalloc-oom", amount, 0);
- return NULL;
-}
-
-/*****************
- * XNFalloc
- * "no failure" realloc, alternate interface to Xalloc w/o Must_have_memory
- *****************/
-
-void *
-XNFalloc (unsigned long amount)
-{
- register void * ptr;
-
- /* zero size requested */
- if (amount == 0) {
- LOG_ALLOC("XNFalloc=0", amount, 0);
- return NULL;
- }
- /* negative size (or size > 2GB) - what do we do? */
- if ((long)amount < 0) {
- /* Diagnostic */
-#ifdef FATALERRORS
- FatalError("Xalloc: XNFalloc(<0)\n");
-#else
- ErrorF("Xalloc warning: XNFalloc(<0) ignored..\n");
-#endif
- LOG_ALLOC("XNFalloc<0", amount, 0);
- return (unsigned long *)NULL;
- }
- ptr = Xalloc(amount);
- if (!ptr)
- {
- FatalError("Out of memory");
- }
- return ptr;
-}
-
-/*****************
- * Xcalloc
- *****************/
-
-void *
-Xcalloc (unsigned long amount)
-{
- void * ret;
-
- ret = Xalloc (amount);
- if (ret != 0
-#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
- && (amount < MIN_LARGE) /* mmaped anonymous mem is already cleared */
-#endif
- )
- bzero ((char *) ret, (int) amount);
- return ret;
-}
-
-/*****************
- * XNFcalloc
- *****************/
-void *
-XNFcalloc (unsigned long amount)
-{
- void * ret;
-
- ret = XNFalloc (amount);
- if (ret != 0
-#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
- && (amount < MIN_LARGE) /* mmaped anonymous mem is already cleared */
-#endif
- )
- bzero ((char *) ret, (int) amount);
- return ret;
-}
-
-/*****************
- * Xrealloc
- *****************/
-
-void *
-Xrealloc (void * ptr, unsigned long amount)
-{
- register unsigned long *new_ptr;
-
- /* zero size requested */
- if (amount == 0) {
- if (ptr)
- Xfree(ptr);
- LOG_REALLOC("Xrealloc=0", ptr, amount, 0);
- return NULL;
- }
- /* negative size (or size > 2GB) - what do we do? */
- if ((long)amount < 0) {
- /* Diagnostic */
-#ifdef FATALERRORS
- FatalError("Xalloc: Xrealloc(<0)\n");
-#else
- ErrorF("Xalloc warning: Xrealloc(<0) ignored..\n");
-#endif
- if (ptr)
- Xfree(ptr); /* ?? */
- LOG_REALLOC("Xrealloc<0", ptr, amount, 0);
- return NULL;
- }
-
- new_ptr = Xalloc(amount);
- if ( (new_ptr) && (ptr) ) {
- unsigned long old_size;
- old_size = ((unsigned long *)ptr)[-2];
-#ifdef XALLOC_DEBUG
- if (MAGIC != ((unsigned long *)ptr)[-1]) {
- if (MAGIC_FREE == ((unsigned long *)ptr)[-1]) {
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: range already freed in Xrealloc() :-(\n");
-#else
- ErrorF("Xalloc error: range already freed in Xrealloc() :-(\a\n");
- sleep(5);
- XfreeTrap();
-#endif
- LOG_REALLOC("Xalloc error: ranged already freed in Xrealloc() :-(",
- ptr, amount, 0);
- return NULL;
- }
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: header corrupt in Xrealloc() :-(\n");
-#else
- ErrorF("Xalloc error: header corrupt in Xrealloc() :-(\n");
- XfreeTrap();
-#endif
- LOG_REALLOC("Xalloc error: header corrupt in Xrealloc() :-(",
- ptr, amount, 0);
- return NULL;
- }
-#endif /* XALLOC_DEBUG */
- /* copy min(old size, new size) */
- memcpy((char *)new_ptr, (char *)ptr, (amount < old_size ? amount : old_size));
- }
- if (ptr)
- Xfree(ptr);
- if (new_ptr) {
- LOG_REALLOC("Xrealloc", ptr, amount, new_ptr);
- return (void *)new_ptr;
- }
- if (Must_have_memory)
- FatalError("Out of memory");
- LOG_REALLOC("Xrealloc", ptr, amount, 0);
- return NULL;
-}
-
-/*****************
- * XNFrealloc
- * "no failure" realloc, alternate interface to Xrealloc w/o Must_have_memory
- *****************/
-
-void *
-XNFrealloc (void * ptr, unsigned long amount)
-{
- if (( ptr = (void *)Xrealloc( ptr, amount ) ) == NULL)
- {
- FatalError( "Out of memory" );
- }
- return ptr;
-}
-
-/*****************
- * Xfree
- * calls free
- *****************/
-
-void
-Xfree(void * ptr)
-{
- unsigned long size;
- unsigned long *pheader;
-
- /* free(NULL) IS valid :-( - and widely used throughout the server.. */
- if (!ptr)
- return;
-
- pheader = (unsigned long *)((char *)ptr - SIZE_HEADER);
-#ifdef XALLOC_DEBUG
- if (MAGIC != pheader[1]) {
- /* Diagnostic */
- if (MAGIC_FREE == pheader[1]) {
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: range already freed in Xrealloc() :-(\n");
-#else
- ErrorF("Xalloc error: range already freed in Xrealloc() :-(\a\n");
- sleep(5);
- XfreeTrap();
-#endif
- LOG_FREE("Xalloc error: ranged already freed in Xrealloc() :-(", ptr);
- return;
- }
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: Header corrupt in Xfree() :-(\n");
-#else
- ErrorF("Xalloc error: Header corrupt in Xfree() :-(\n");
- XfreeTrap();
-#endif
- LOG_FREE("Xalloc error: Header corrupt in Xfree() :-(", ptr);
- return;
- }
-#endif /* XALLOC_DEBUG */
-
- size = pheader[0];
- if (size <= MAX_SMALL) {
- int indx;
- /*
- * small block
- */
-#ifdef SIZE_TAIL
- if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) {
- /* Diagnostic */
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
-#else
- ErrorF("Xalloc error: Tail corrupt in Xfree() for small block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
- XfreeTrap();
-#endif
- LOG_FREE("Xalloc error: Tail corrupt in Xfree() for small block", ptr);
- return;
- }
-#endif /* SIZE_TAIL */
-
-#ifdef XFREE_ERASES
- memset(ptr,0xF0,size);
-#endif /* XFREE_ERASES */
-#ifdef XALLOC_DEBUG
- pheader[1] = MAGIC_FREE;
-#endif
- /* put this small block at the head of the list */
- indx = (size-1) / SIZE_STEPS;
- *(unsigned long **)(ptr) = free_lists[indx];
- free_lists[indx] = (unsigned long *)ptr;
- LOG_FREE("Xfree", ptr);
- return;
-
-#if defined(HAS_MMAP_ANON) || defined(MMAP_DEV_ZERO)
- } else if (size >= MIN_LARGE) {
- /*
- * large block
- */
-#ifdef SIZE_TAIL
- if (MAGIC2 != ((unsigned long *)((char *)ptr + size))[0]) {
- /* Diagnostic */
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]);
-#else
- ErrorF("Xalloc error: Tail corrupt in Xfree() for big block (adr=0x%x, val=0x%x)\n",(char *)ptr+size,((unsigned long *)((char *)ptr + size))[0]);
- XfreeTrap();
-#endif
- LOG_FREE("Xalloc error: Tail corrupt in Xfree() for big block", ptr);
- return;
- }
- size += SIZE_TAIL;
-#endif /* SIZE_TAIL */
-
- LOG_FREE("Xfree", ptr);
- size += SIZE_HEADER;
- munmap((caddr_t)pheader, (size_t)size);
- /* no need to clear - mem is inaccessible after munmap.. */
-#endif /* HAS_MMAP_ANON */
-
- } else {
- /*
- * medium sized block
- */
-#ifdef SIZE_TAIL
- if (MAGIC2 != *(unsigned long *)((char *)ptr + size)) {
- /* Diagnostic */
-#ifdef FATALERRORS
- XfreeTrap();
- FatalError("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
-#else
- ErrorF("Xalloc error: Tail corrupt in Xfree() for medium block (adr=0x%x, val=0x%x)\n",(char *)ptr + size,*(unsigned long *)((char *)ptr + size));
- XfreeTrap();
-#endif
- LOG_FREE("Xalloc error: Tail corrupt in Xfree() for medium block", ptr);
- return;
- }
-#endif /* SIZE_TAIL */
-
-#ifdef XFREE_ERASES
- memset(pheader,0xF0,size+SIZE_HEADER);
-#endif /* XFREE_ERASES */
-#ifdef XALLOC_DEBUG
- pheader[1] = MAGIC_FREE;
-#endif
-
- LOG_FREE("Xfree", ptr);
- free((char *)pheader);
- }
-}
-
-void
-OsInitAllocator (void)
-{
- static Bool beenhere = FALSE;
-
- if (beenhere)
- return;
- beenhere = TRUE;
-
-#if defined(HAS_MMAP_ANON) || defined (MMAP_DEV_ZERO)
- pagesize = -1;
-#if defined(_SC_PAGESIZE) || defined(HAS_SC_PAGESIZE)
- pagesize = sysconf(_SC_PAGESIZE);
-#endif
-#ifdef _SC_PAGE_SIZE
- if (pagesize == -1)
- pagesize = sysconf(_SC_PAGE_SIZE);
-#endif
-#ifdef HAS_GETPAGESIZE
- if (pagesize == -1)
- pagesize = getpagesize();
-#endif
-#ifdef PAGE_SIZE
- if (pagesize == -1)
- pagesize = PAGE_SIZE;
-#endif
- if (pagesize == -1)
- FatalError("OsInitAllocator: Cannot determine page size\n");
-#endif
-
- /* set up linked lists of free blocks */
- bzero ((char *) free_lists, MAX_SMALL/SIZE_STEPS*sizeof(unsigned long *));
-
-#ifdef MMAP_DEV_ZERO
- /* open /dev/zero on systems that have mmap, but not MAP_ANON */
- if (devzerofd < 0) {
- if ((devzerofd = open("/dev/zero", O_RDWR, 0)) < 0)
- FatalError("OsInitAllocator: Cannot open /dev/zero (errno=%d)\n",
- errno);
- }
-#endif
-
-#ifdef XALLOC_LOG
- /* reset the log file to zero length */
- {
- FILE *f;
- f = fopen(XALLOC_LOG_FILE, "w");
- if (NULL!=f)
- fclose(f);
- }
-#endif
-}
-
-#else /* !INTERNAL_MALLOC */
-/* This is to avoid an empty .o */
-static int no_internal_xalloc;
-#endif /* INTERNAL_MALLOC */
diff --git a/nx-X11/programs/Xserver/os/xdmauth.c b/nx-X11/programs/Xserver/os/xdmauth.c
index 92fbde478..a89c5b0c0 100644
--- a/nx-X11/programs/Xserver/os/xdmauth.c
+++ b/nx-X11/programs/Xserver/os/xdmauth.c
@@ -240,7 +240,7 @@ XdmClientAuthTimeout (long now)
prev->next = next;
else
xdmClients = next;
- xfree (client);
+ free (client);
}
else
prev = client;
@@ -260,20 +260,20 @@ XdmAuthorizationValidate (unsigned char *plain, int length,
*reason = "Bad XDM authorization key length";
return NULL;
}
- client = (XdmClientAuthPtr) xalloc (sizeof (XdmClientAuthRec));
+ client = (XdmClientAuthPtr) malloc (sizeof (XdmClientAuthRec));
if (!client)
return NULL;
XdmClientAuthDecode (plain, client);
if (!XdmcpCompareKeys (&client->rho, rho))
{
- xfree (client);
+ free (client);
if (reason)
*reason = "Invalid XDM-AUTHORIZATION-1 key (failed key comparison)";
return NULL;
}
for (i = 18; i < 24; i++)
if (plain[i] != 0) {
- xfree (client);
+ free (client);
if (reason)
*reason = "Invalid XDM-AUTHORIZATION-1 key (failed NULL check)";
return NULL;
@@ -288,15 +288,15 @@ XdmAuthorizationValidate (unsigned char *plain, int length,
#if defined(TCPCONN) || defined(STREAMSCONN)
if (family == FamilyInternet &&
memcmp((char *)addr, client->client, 4) != 0) {
- xfree (client);
- xfree (addr);
+ free (client);
+ free (addr);
if (reason)
*reason = "Invalid XDM-AUTHORIZATION-1 key (failed address comparison)";
return NULL;
}
#endif
- xfree (addr);
+ free (addr);
}
}
now = time(0);
@@ -309,7 +309,7 @@ XdmAuthorizationValidate (unsigned char *plain, int length,
XdmClientAuthTimeout (now);
if (abs (client->time - now) > TwentyMinutes)
{
- xfree (client);
+ free (client);
if (reason)
*reason = "Excessive XDM-AUTHORIZATION-1 time offset";
return NULL;
@@ -318,7 +318,7 @@ XdmAuthorizationValidate (unsigned char *plain, int length,
{
if (XdmClientAuthCompare (existing, client))
{
- xfree (client);
+ free (client);
if (reason)
*reason = "XDM authorization key matches an existing client!";
return NULL;
@@ -364,7 +364,7 @@ XdmAddCookie (unsigned short data_length, char *data, XID id)
/* the first octet of the key must be zero */
if (key_bits[0] != '\0')
return 0;
- new = (XdmAuthorizationPtr) xalloc (sizeof (XdmAuthorizationRec));
+ new = (XdmAuthorizationPtr) malloc (sizeof (XdmAuthorizationRec));
if (!new)
return 0;
new->next = xdmAuth;
@@ -386,7 +386,7 @@ XdmCheckCookie (unsigned short cookie_length, char *cookie,
/* Auth packets must be a multiple of 8 bytes long */
if (cookie_length & 7)
return (XID) -1;
- plain = (unsigned char *) xalloc (cookie_length);
+ plain = (unsigned char *) malloc (cookie_length);
if (!plain)
return (XID) -1;
for (auth = xdmAuth; auth; auth=auth->next) {
@@ -395,11 +395,11 @@ XdmCheckCookie (unsigned short cookie_length, char *cookie,
{
client->next = xdmClients;
xdmClients = client;
- xfree (plain);
+ free (plain);
return auth->id;
}
}
- xfree (plain);
+ free (plain);
return (XID) -1;
}
@@ -412,13 +412,13 @@ XdmResetCookie (void)
for (auth = xdmAuth; auth; auth=next_auth)
{
next_auth = auth->next;
- xfree (auth);
+ free (auth);
}
xdmAuth = 0;
for (client = xdmClients; client; client=next_client)
{
next_client = client->next;
- xfree (client);
+ free (client);
}
xdmClients = (XdmClientAuthPtr) 0;
return 1;
@@ -431,19 +431,19 @@ XdmToID (unsigned short cookie_length, char *cookie)
XdmClientAuthPtr client;
unsigned char *plain;
- plain = (unsigned char *) xalloc (cookie_length);
+ plain = (unsigned char *) malloc (cookie_length);
if (!plain)
return (XID) -1;
for (auth = xdmAuth; auth; auth=auth->next) {
XdmcpUnwrap (cookie, (unsigned char *)&auth->key, plain, cookie_length);
if ((client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, NULL, NULL)) != NULL)
{
- xfree (client);
- xfree (cookie);
+ free (client);
+ free (cookie);
return auth->id;
}
}
- xfree (cookie);
+ free (cookie);
return (XID) -1;
}
@@ -492,7 +492,7 @@ XdmRemoveCookie (unsigned short data_length, char *data)
prev->next = auth->next;
else
xdmAuth = auth->next;
- xfree (auth);
+ free (auth);
return 1;
}
}
diff --git a/nx-X11/programs/Xserver/os/xdmcp.c b/nx-X11/programs/Xserver/os/xdmcp.c
index 4181e52ce..d48012759 100644
--- a/nx-X11/programs/Xserver/os/xdmcp.c
+++ b/nx-X11/programs/Xserver/os/xdmcp.c
@@ -407,7 +407,7 @@ XdmcpRegisterAuthentication (
AuthenticationNames.length + 1) &&
XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas,
AuthenticationDatas.length + 1) &&
- (newFuncs = (AuthenticationFuncsPtr) xalloc (
+ (newFuncs = (AuthenticationFuncsPtr) malloc (
(AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec)))))
{
XdmcpDisposeARRAY8 (&AuthenticationName);
@@ -419,7 +419,7 @@ XdmcpRegisterAuthentication (
newFuncs[AuthenticationNames.length-1].Validator = Validator;
newFuncs[AuthenticationNames.length-1].Generator = Generator;
newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth;
- xfree (AuthenticationFuncsList);
+ free (AuthenticationFuncsList);
AuthenticationFuncsList = newFuncs;
AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName;
AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData;
@@ -507,18 +507,18 @@ XdmcpRegisterConnection (
return;
}
}
- newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8));
+ newAddress = (CARD8 *) malloc (addrlen * sizeof (CARD8));
if (!newAddress)
return;
if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1))
{
- xfree (newAddress);
+ free (newAddress);
return;
}
if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses,
ConnectionAddresses.length + 1))
{
- xfree (newAddress);
+ free (newAddress);
return;
}
ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type;
@@ -548,12 +548,12 @@ XdmcpRegisterAuthorization (char *name, int namelen)
ARRAY8 authName;
int i;
- authName.data = (CARD8 *) xalloc (namelen * sizeof (CARD8));
+ authName.data = (CARD8 *) malloc (namelen * sizeof (CARD8));
if (!authName.data)
return;
if (!XdmcpReallocARRAYofARRAY8 (&AuthorizationNames, AuthorizationNames.length +1))
{
- xfree (authName.data);
+ free (authName.data);
return;
}
for (i = 0; i < namelen; i++)
diff --git a/nx-X11/programs/Xserver/os/xprintf.c b/nx-X11/programs/Xserver/os/xprintf.c
index 4423208ff..1bcb36d3c 100644
--- a/nx-X11/programs/Xserver/os/xprintf.c
+++ b/nx-X11/programs/Xserver/os/xprintf.c
@@ -1,5 +1,5 @@
/*
- * printf routines which xalloc their buffer
+ * printf routines which malloc their buffer
*/
/*
* Copyright (c) 2004 Alexander Gottwald
@@ -111,7 +111,7 @@ Xvprintf(const char *format, va_list va)
size = vsnprintf(NULL, 0, format, va2);
va_end(va2);
- ret = (char *)Xalloc(size + 1);
+ ret = (char *)malloc(size + 1);
if (ret == NULL)
return NULL;