AFNI itself does not define a malloc() function; the most it does is use a #define to change malloc() invocations IN ITS OWN SOURCE CODE to mcw_malloc(), which will then call malloc().
It is possible that the X11 system you are linking to is providing its own malloc function. In that case, you might want to put the MPI library first on the link command line, so that its malloc will be picked up, and then put it on the command line again later if needed (that is, repeat the '-lmpich' or whatever that invokes the MPI library).