Running your sketch on a Leonardo with no peripherals attached I get this:
Serial started.
Made it to the config fn.
Made it to the first CtrlReg.
Addressed CtrlReg1.
Enabled ACTIVE mode.
Error code:2
Ended transmission to CtrlReg1.
Made it to the second CtrlReg.
Addressed CtrlReg2.
Enabled auto-reset.
Error code: 2
Ended transmission to CtrlReg2.
Magnetometer config done.
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
x=768, y=768, z=768
I would try my I2C scanner from this page:
That will tell you if it detects the I2C peripheral, and if so, on what address.
There is a problem with the stock I2C library that a mis-transmission may cause it to hang. This will generally happen on the Wire.endTransmission() line which is the one which actually sends the data. The other lines just put the data into a buffer. There is another library (link on the page above) which will time-out if it cannot communicate. You might want to check your wiring, the pull-up resistors, etc. Also try slowing down the I2C communications (how to do that is explained on my page).