dumpwallet always corrupts my wallet I have repeated this process a few times, always with the same error.

In one terminal,

./bitcoind -testnet

in another

./bitcoind -testnet getnewaddress

mgj4Y8AvckxborhQzqFAhppcGVGFExqJvB

./bitcoind -testnet dumpwallet /path/to/testnet3/wallet.dat

error: {"code":-1,"message":"CDB() : can't open database file wallet.dat, error 22"}

./bitcoind -testnet stop

Bitcoin server stopping

In the original terminal, 

libc++abi.dylib: terminate called throwing an exception
Abort trap: 6

Then I type

./bitcoind -testnet 

Error: wallet.dat corrupt, salvage failed

Anybody have an idea what is going on? I updated my bitcoin to the latest on github. I also searched for the error 22 but didn't find anything. I'm guessing CDB means corrupted database. I also looked in debug.log, but I didn't see anything weird. 

I know it is the dumpwallet command that is breaking it, because when I omit it from this process, nothing breaks. 

The same things happens on the mainnet, altho I have not tested it as much.

Am I using the dumpwallet command incorrectly?
The path you pass to dumpwallet is the filename of the dump.

If you pass the name of your wallet database itself (or any existing file, actually), it will get overwritten.