Check out the concept of fault injection -- you can wrap all of the malloc() calls and the systematically cause each one to fail. You might want to combine that with valgrind to make sure you don&#x27;t end up doing undefined things after a malloc failure.<p>You can also use that wrapping technique to test _mesa_error_no_memory(), by setting the state to &quot;all mallocs fail&quot; and then calling it. Hint: Don&#x27;t call fprintf, don&#x27;t use stdio, call write() directly.<p>Fault injection can&#x27;t cover all of the combinations of all inputs and all places to fail, but it&#x27;s a lot better than nothing.