Thank you for the response. I completely agree with your response. The
reason why I asked this question is because I remember seeing len(unsigned
long *lengths;) dynamically allocated in the MYSQL manual some time
ago(when I was running mysql 3.23.30). So, I wonder if there was a change
in the return value of mysql_fetch_lenghts() in mysql 3.23.58.
Otherwise, I made a mistake in dynamically allocating memory for len. I
must have misunderstood.
Thank you.
-Teresa
----------------------------------------------------------------------------------------
This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit written
agreement or government initiative expressly permitting the use of e-mail
for such purpose.
----------------------------------------------------------------------------------------
Dan Nelson
<dnelson To: Teresa A Narvaez/FED/CSC@CSC
@allantgroup.com cc: mysql@stripped
> Subject: Re: mysql_fetch_lengths()
12/23/2004 12:19
PM
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
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=1