lawremi / rtracklayer

R interface to genome annotation files and the UCSC genome browser
Other
29 stars 17 forks source link

Bigbed io feature #28

Closed sanchit-saini closed 4 years ago

sanchit-saini commented 4 years ago

As I told you bigBedIntervalToRow internally allocating memory with cloneString

bigBedIntervalToRow Calling statement

bigBedIntervalToRow Body

I tried to free it with below code

for (int i = 3; i < fieldCount; ++i)
  freeMem(row[i]);

but R throw this error at run-time

free(): invalid pointer
lawremi commented 4 years ago

Not sure what's going wrong. It's possible that the number of fields in that row is smaller than the number globally declared. The bigBedIntervalToRow() function returns the actual number of fields. Perhaps that is smaller than fieldCount.

sanchit-saini commented 4 years ago

Not sure what's going wrong. It's possible that the number of fields in that row is smaller than the number globally declared. The bigBedIntervalToRow() function returns the actual number of fields. Perhaps that is smaller than fieldCount.

I tried to run it with the returned number of fields, but got the same error.

lawremi commented 4 years ago

Here's my new theory. The pointers in row come from chopByChar() in common.c. It's a little tricky in that it populates row with pointers from within the cloned parent string. Thus, only the first element in row points to a free()able string, allocated by malloc(). The other strings pointed to by row will be freed when you free the first string.

See this for some explanation: https://stackoverflow.com/questions/20297524/c-free-invalid-pointer

sanchit-saini commented 4 years ago

Here's my new theory. The pointers in row come from chopByChar() in common.c. It's a little tricky in that it populates row with pointers from within the cloned parent string. Thus, only the first element in row points to a free()able string, allocated by malloc(). The other strings pointed to by row will be freed when you free the first string.

See this for some explanation: https://stackoverflow.com/questions/20297524/c-free-invalid-pointer

Thanks, this solved the problem.