/*++ /* NAME /* mymalloc 3 /* SUMMARY /* memory management wrappers /* SYNOPSIS /* #include <mymalloc.h> /* /* void *mymalloc(len) /* ssize_t len; /* /* void *myrealloc(ptr, len) /* void *ptr; /* ssize_t len; /* /* void myfree(ptr) /* void *ptr; /* /* char *mystrdup(str) /* const char *str; /* /* char *mystrndup(str, len) /* const char *str; /* ssize_t len; /* /* void *mymemdup(ptr, len) /* const void *ptr; /* ssize_t len; /* DESCRIPTION /* This module performs low-level memory management with error /* handling. A call of these functions either succeeds or it does /* not return at all. /* /* To save memory, zero-length strings are shared and read-only. /* The caller must not attempt to modify the null terminator. /* This code is enabled unless NO_SHARED_EMPTY_STRINGS is /* defined at compile time (for example, you have an sscanf() /* routine that pushes characters back into its input). /* /* mymalloc() allocates the requested amount of memory. The memory /* is not set to zero. /* /* myrealloc() resizes memory obtained from mymalloc() or myrealloc() /* to the requested size. The result pointer value may differ from /* that given via the \fIptr\fR argument. /* /* myfree() takes memory obtained from mymalloc() or myrealloc() /* and makes it available for other use. /* /* mystrdup() returns a dynamic-memory copy of its null-terminated /* argument. This routine uses mymalloc(). /* /* mystrndup() returns a dynamic-memory copy of at most \fIlen\fR /* leading characters of its null-terminated /* argument. The result is null-terminated. This routine uses mymalloc(). /* /* mymemdup() makes a copy of the memory pointed to by \fIptr\fR /* with length \fIlen\fR. The result is NOT null-terminated. /* This routine uses mymalloc(). /* SEE ALSO /* msg(3) diagnostics interface /* DIAGNOSTICS /* Problems are reported via the msg(3) diagnostics routines: /* the requested amount of memory is not available; improper use /* is detected; other fatal errors. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA /* /* Wietse Venema /* Google, Inc. /* 111 8th Avenue /* New York, NY 10011, USA
/*--*/
/* *Structureofanannotatedmemoryblock.Inordertodetectspurious *free()callsweprependasignaturetomemorygiventotheapplication. *Inordertodetectaccesstofree()dblocks,overwriteeachblockassoon *asitispassedtomyfree().Withthecodebelow,theuserdatahas *integeralignmentorbetter.
*/ typedefstruct MBLOCK { int signature; /* set when block is active */
ssize_t length; /* user requested length */ union {
ALIGN_TYPE align; char payload[1]; /* actually a bunch of bytes */
} u;
} MBLOCK;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.