You seem to be using this malloc, strcpy, strcat, strcat several times throughout this file. It might make sense to move that into a static function that's used by all places in this file, e.g.:

```
static char *
bt_path_join(const char *directory, const char *filename)
{
    char *result = (char *)malloc(strlen(directory) + 1 + strlen(filename) + 1);
    sprintf(result, "%s/%s", directory, filename);
    return result;
}
```