E' corretto anche così, ma fai un passaggio in più.
Visto che allochi temp, perché non usare direttamente quella?