# PetscMallocValidate
Test the memory for corruption.  This can be called at any time between `PetscInitialize()` and `PetscFinalize()` 
## Synopsis
```
#include "petscsys.h" 
PetscErrorCode PetscMallocValidate(int line, const char function[], const char file[])
```

## Input Parameters

- ***line -*** line number where call originated.
- ***function -*** name of function calling
- ***file -*** file where function is



## Return value
The number of errors detected.

Options Database Keys:.

- ***-malloc_test -*** turns this feature on when PETSc was not configured with --with-debugging=0
- ***-malloc_debug -*** turns this feature on anytime



## Output Effect
Error messages are written to stdout.




## Notes
This is only run if `PetscMallocSetDebug()` has been called which is set by -malloc_test (if debugging is turned on) or -malloc_debug (any time)

You should generally use `CHKMEMQ` as a short cut for calling this  routine.

The Fortran calling sequence is simply `PetscMallocValidate(ierr)`

No output is generated if there are no problems detected.


## Developers Note
Uses the flg TRdebugLevel (set as the first argument to `PetscMallocSetDebug()`) to determine if it should run


## See Also
 `CHKMEMQ`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/sys/memory/mtr.c.html#PetscMallocValidate">src/sys/memory/mtr.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/sys/memory/mtr.c)


[Index of all Sys routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
