Dmalloc Logo
Home

Documentation
Downloads
Forums
Releases

Search this site:

Donations:
If dmalloc has saved you or your company time or money, please use your credit-card or PayPal account to donate to the cause.

Dmalloc Tutorial: 3.6 Description of the Internal Error Codes
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6 Description of the Internal Error Codes

The following error codes are defined in `error_val.h'. They are used by the library to indicate a detected problem. They can be caused by the user (`ERROR_TOO_BIG') or can indicate an internal library problem (`ERROR_SLOT_CORRUPT'). The `dmalloc' utility can give you the string version of the error with the -e argument:

 
$ dmalloc -e 60
dmalloc: dmalloc_errno value '60' = 
   'pointer is not on block boundary'

Here are the error codes set by the library. They are non contiguous on purpose because I add and delete codes all of the time and there are sections for various error-code types.

1 (ERROR_NONE) no error

No error. It is good coding practice to set the no-error code to be non-0 value because it forces you to set it explicitly.

2 (INVALID_ERROR)

Invalid error number. If the library outputs this error then your dmalloc utility may be out of date with the library you linked against. This will be returned with all error codes not listed here.

10 (ERROR_BAD_SETUP) initialization and setup failed

Bad setup value. This is currently unused but it is intended to report on invalid setup configuration information.

11 (ERROR_IN_TWICE) malloc library has gone recursive

Library went recursive. This usually indicates that you are not using the threaded version of the library. Or if you are then you are not using the `-o' "lock-on" option. See section Using the Library with a Thread Package.

13 (ERROR_LOCK_NOT_CONFIG) thread locking has not been configured

Thread locking has not been configured. This indicates that you attempted to use the `-o' "lock-on" option without linking with the thread version of the library. You should probably be using -ldmallocth not -ldmalloc when you are linking. Or you should include …/lib/libdmallocth.a on your compilation line.

20 (ERROR_IS_NULL) pointer is null

Pointer is null. The program passed a NULL (0L) pointer to free and you have the error-free-null token enabled.

21 (ERROR_NOT_IN_HEAP) pointer is not pointing to heap data space

Pointer is not pointing to heap data space. This means that the program passed an out-of-bounds pointer to free or realloc. This could be someone trying to work with a wild pointer or trying to free a pointer from a different source than malloc.

22 (ERROR_NOT_FOUND) cannot locate pointer in heap

Cannot locate pointer in heap. The user passed in a pointer which the heap did not know about. Either this pointer was allocated by some other mechanism (like mmap or sbrk directly) or it is a random invalid pointer.

In some rare circumstances, sometimes seen with shared libraries, there can be two separate copies of the dmalloc library in a program. Each one does not know about the pointers allocated by the other.

23 (ERROR_IS_FOUND) found pointer the user was looking for

This indicates that the pointer specified in the address part of the environmental variable was discovered by the library. See section Environment Variable Name and Features. This error is useful so you can put a breakpoint in a debugger to find where a particular address was allocated. See section Using Dmalloc With a Debugger.

24 (ERROR_BAD_FILE) possibly bad .c filename pointer

A possibly invalid filename was discovered in the dmalloc administrative sections. This could indicate some corruption of the internal tables. It also could mean that you have a source file whose name is longer than 100 characters. See MAX_FILE_LENGTH in the `settings.dist' file.

25 (ERROR_BAD_LINE) possibly bad .c file line-number

A line-number was out-of-bounds in the dmalloc administrative sections. This could indicate some corruption of the internal tables. It also could mean that you have a source file containing more than 30000 lines of code. See MAX_LINE_NUMBER in the `settings.dist' file.

26 (ERROR_UNDER_FENCE) failed UNDER picket-fence magic-number check

This indicates that a pointer had its lower bound picket-fence magic number overwritten. If the check-fence token is enabled, the library writes magic values above and below allocations to protect against overflow. Most likely this is because a pointer below it went past its allocate and wrote into the next pointer's space.

27 (ERROR_OVER_FENCE) failed OVER picket-fence magic-number check

This indicates that a pointer had its upper bound picket-fence magic space overwritten. If the check-fence token is enabled, the library writes magic values above and below allocations to protect against overflow. Most likely this is because an array or string allocation wrote past the end of the allocation.

Check for improper usage of strcat, sprintf, strcpy, and any other functions which work with strings and do not protect themselves by tracking the size of the string. These functions should always be replaced with: strncat, snprintf, strncpy, and others.

28 (ERROR_WOULD_OVERWRITE) use of pointer would exceed allocation

This error is generated by the function pointer checking code usually enabled with the check-funcs token. Dmalloc overloads a number of string and memory copying functions and verifies that the buffers (if allocated in the heap) would not be overwritten by the function.

30 (ERROR_NOT_START_BLOCK) pointer is not to start of memory block

This indicates that the user passed in a pointer to be freed or reallocated that was not at the start of the allocation. You would get this error, for example, if you allocate and get pointer X but then try to free X+1.

40 (ERROR_BAD_SIZE) invalid allocation size

This error indicates that a size value in the internal structures of the library were corrupted. This could be a random pointer problem, pointer overflow, or some other corruption.

41 (ERROR_TOO_BIG) largest maximum allocation size exceeded

An allocation asked for memory larger than the configured maximum. This is a user configured setting. See LARGEST_ALLOCATION in the `settings.dist' file. It is used to protect against wild allocation sizes. If you have super large allocation sizes then you should tune the LARGEST_ALLOCATION value appropriately.

43 (ERROR_ALLOC_FAILED) could not grow heap by allocating memory

The library could not allocate more heap space and the program has run out of memory. This could indicate that you've overflowed some system imposed limit. On many operation systems, the ulimit call can tune system defaults. The library uses a lot more memory compared to the system malloc library because it stores a lot more information about the allocated pointers.

NOTE: This also may be due to an inability of your operating system to use the mmap system call to allocate memory. You may need to force the USE_MMAP setting to be 0. Please use the forums at URL http://dmalloc.com/ to report issues with this.

45 (ERROR_OVER_LIMIT) over user specified allocation limit

The library has allocated more memory than was specified in the memory-limit environmental variable. See section Environment Variable Name and Features.

60 (ERROR_NOT_ON_BLOCK) pointer is not on block boundary

The user tried to free or realloc a pointer that was not pointing to a block boundary. You would get this error, for example, if you allocate and get pointer X but then try to free X+1.

61 (ERROR_ALREADY_FREE) tried to free previously freed pointer

The user tried to free a pointer than has already been freed. This is a very common mistake and can lead to serious problems. It can be because a destructor is being called twice for some reason. Although tracking down the specific source is highly recommended, it is good to set pointers to NULL (0L) after you free them as a rule.

67 (ERROR_FREE_OVERWRITTEN) free space has been overwritten

If either the free-blank or check-blank tokens are enabled then the library will overwrite memory when it is freed with the "dmalloc-free" byte (hex 0xdf, octal 0337, decimal 223). If the program writes into this space, then the library will detect the write and trigger this error. This could indicate that the program is using a pointer after it has been freed.

70 (ERROR_ADMIN_LIST) bad admin structure list

An internal corruption in the library's administrative structures has been detected. This could be a random pointer problem, pointer overflow, or some other corruption.

72 (ERROR_ADDRESS_LIST) internal address list corruption

An internal corruption in the library's administrative structures has been detected. This could be a random pointer problem, pointer overflow, or some other corruption.

73 (ERROR_SLOT_CORRUPT) internal memory slot corruption

An internal corruption in the library's administrative structures has been detected. This could be a random pointer problem, pointer overflow, or some other corruption.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated by Gray Watson on May, 16 2007 using texi2html 1.76.

This work is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.
This page should be W3C Valid XHTML and should work with most browsers.