Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

memory leak questions about c programming

Tags:

c

memory-leaks

Will this function cause memory leak?

The function is :

double list(double *list2){
  double *list3=(double *)malloc(sizeof(double));
  some operations...
  return *list3;
}

update:

could this help?

int main(){

 operations...
 double list4;
 list4=list(&list4);
 free(&list4);

 return 0;
}
like image 881
makeapp Avatar asked Dec 31 '25 06:12

makeapp


1 Answers

Yes, it does: it is returning a copy of the value of what is stored in the allocated memory, but the allocated memory itself is leaked (because the address has been "lost").

like image 121
Scott Hunter Avatar answered Jan 01 '26 21:01

Scott Hunter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!