In the last episode (Dec 23), Teresa A Narvaez said:
> We were running mysql 3.22.30 on an Tru 64 Alpha server OSF 4.0F. We
> recently upgraded to mysql 3.23.58 on the same server.
>
> In the code fragment below, there is a memory leak at line 8 because
> mysql_fetch_lenghts returns an array of unsigned long integers
> representing the size of each column. So, has the retun value of
> mysql_fetch_lengths() been the same for mysql 3.22.30 and 3.23.58?
>
> 1. unsigned long *lengths;
> 2. unsigned int num_fields;
> 3. unsigned int i;
> 4. MYSQL_RES *result=NULL;
> 5. row = mysql_fetch_row(result);
> 6. if (row)
> 7. {
> 8. len = malloc(sizeof(unsigned long) * mysql_num_fields(result));
> 9. num_fields = mysql_num_fields(result);
> 10. lengths = mysql_fetch_lengths(result);
> 11. for(i = 0; i < num_fields; i++)
> 12. {
> 13. printf("Column %u is %lu bytes in length.\n", i, lengths[i]);
> 14. }
> 15. free(len)
> 16.}
The memory allocated at line 8 is freed at line 15. In fact, it's
never used at all. The array returned by mysql_fetch_lengths is an
internal array that is freed by mysql_free_result(); you don't need to
allocate it or free it.
--
Dan Nelson
dnelson@stripped