I have written this code, and at first glance it does what I want, however I am worried that a) I am overwriting the array that is apssed from chord.getPattern() b) Im getting a memory leak that I want to get rid of, and c) is there generally a /what is the neater way to do it:

Code:
uint8_t* ChordBuilder::invert(uint8_t count, Chord chord) {
	temp = chord.getPattern();
	chord.invert(true);
	//TODO count is how many times to invert. Moves root aswell however

	for (uint8_t i = 0; i < count; i++){
		temp = doInversion(temp, chord.getSize());
	}
	return temp;
}

uint8_t* ChordBuilder::doInversion(uint8_t* pattern, uint8_t size) {

	temp = new uint8_t[size];
	temp[0] = pattern[1];
	for (int i = 1; i < size - 1; i++) {
		temp[i] = pattern[i + 1];
	}
	temp[size - 1] = pattern[0] + 12;
	return temp;
}
temp is a member variable of ChordBuilder - and is expressed as:
Code:
 uint8_t* temp;
I dont want the pattern that chord stores, and passes with getPattern() to change - I fear it is at the moment?
I would rather not use the "new" but I cant think how to get rid of it, however Im not sure where I would need to put the "delete"?

Thanks
Alex