Theory of why this doesn't really work?

You can make up tests like that all day and get different results. The way the compiler allocates temporary variables may affect things. It might "inline" the function in one place and not another. Once you "break the rules" and use variables when they are out of scope (eg. doing malloc/free and then continuing to use the allocated memory) then all bets are off. It may "work", for a while, it may not.