Link to home
Start Free TrialLog in
Avatar of perlperl
perlperl

asked on

Does this leak memory

struct some_struct {

}

std::vector<some_struct *> list_of_struct;
list_of_struct.push_back(new some_struct());

some_struct* remove_first_member() {
	std::vector<some_struct *>::iterator it( list_of_struct.begin());
	some_struct  *temp = *it;
	 list_of_struct.erase(it);
	return temp;
}

// somewhere in main I am calling
remove_first_member(); // There is no lvalue even though the function returns pointer
                                        // to some_struct

Open in new window


Will this leak memory?
Avatar of perlperl
perlperl

ASKER

OR should I do something like this to avoid memory leak?

some_struct* temp = remove_first_member();
delete temp;
ASKER CERTIFIED SOLUTION
Avatar of perlperl
perlperl

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial