C acoustic recording program script hang

I use odroidN2+ and audio interface to record the acoustic data 24/7. After recording several files, the program hang.
When I check the program with the valgrind to check the heap summary, it mentioned as below. I suspect the issue was due to portaudio library. Therefore, I compiled the portaudio library inside the odroidN2+ but the issue still exists.

==1309067== HEAP SUMMARY:
==1309067==     in use at exit: 42,461 bytes in 81 blocks
==1309067==   total heap usage: 14,115 allocs, 14,034 frees, 1,489,720 bytes allocated
==1309067==
==1309067== 11 bytes in 1 blocks are definitely lost in loss record 3 of 72
==1309067==    at 0x4849D8C: malloc (in /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_memcheck-arm64-linux.so)
==1309067==    by 0x10A383: main (in /home/odroid/acoustic/Recorder/Recorder_N2plus_10min)
==1309067==

==1309067== 112 bytes in 1 blocks are definitely lost in loss record 54 of 72
==1309067==    at 0x484C0A4: calloc (in /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_memcheck-arm64-linux.so)
==1309067==    by 0x6243C2F: ???
==1309067==    by 0x4B4BD03: ??? (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x4B4C2F7: ??? (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x4B4F2CF: snd_pcm_open (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x48A6593: ??? (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x48A8B83: ??? (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x48AB60B: PaAlsa_Initialize (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x489F723: Pa_Initialize (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x10A4FB: main (in /home/odroid/acoustic/Recorder/Recorder_N2plus_10min)
==1309067==
==1309067== 1,360 bytes in 1 blocks are definitely lost in loss record 63 of 72
==1309067==    at 0x484C0A4: calloc (in /usr/lib/aarch64-linux-gnu/valgrind/vgpreload_memcheck-arm64-linux.so)
==1309067==    by 0x62572AB: ???
==1309067==    by 0x4B4BD03: ??? (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x4B4C2F7: ??? (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x4B4F2CF: snd_pcm_open (in /usr/lib/aarch64-linux-gnu/libasound.so.2.0.0)
==1309067==    by 0x48A6593: ??? (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x48A8B83: ??? (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x48AB60B: PaAlsa_Initialize (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x489F723: Pa_Initialize (in /usr/lib/aarch64-linux-gnu/libportaudio.so.2.0.0)
==1309067==    by 0x10A4FB: main (in /home/odroid/acoustic/Recorder/Recorder_N2plus_10min)
==1309067==
==1309067== LEAK SUMMARY:
==1309067==    definitely lost: 1,483 bytes in 3 blocks
==1309067==    indirectly lost: 0 bytes in 0 blocks
==1309067==      possibly lost: 0 bytes in 0 blocks
==1309067==    still reachable: 40,978 bytes in 78 blocks
==1309067==         suppressed: 0 bytes in 0 blocks
==1309067== Reachable blocks (those to which a pointer was found) are not shown.
==1309067== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==1309067==
==1309067== For lists of detected and suppressed errors, rerun with: -s
==1309067== ERROR SUMMARY: 160 errors from 23 contexts (suppressed: 0 from 0)

May I know how can I solve this recording hang issue?
My recording is as follows:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <portaudio.h>
#include <sndfile.h>
#include <time.h>
#include <libconfig.h>
#include <pthread.h>
#define FRAMES_PER_BUFFER (512)
#if 1
#define PA_SAMPLE_TYPE  paFloat32
typedef float SAMPLE;
#define SAMPLE_SILENCE  (0.0f)
#define PRINTF_S_FORMAT "%.8f"
#elif 1
#elif 0
#else
#endif
const char * CurrentDateTime();
char* concat(char *s1, char *s2);
void *callPythonScript(void *vargp);
char wavefilename[45];
char equip[15];
SNDFILE      *outfileCB;
SF_INFO sfinfo;
char * FileNameHead;
int filesize,NUM_CHANNELS,SAMPLE_RATE,duration;
typedef struct
{
    int          frameIndex; 
    int          maxFrameIndex;
    SAMPLE      *recordedSamples;
}
paTestData;
static int recordCallback(const void *inputBuffer, void *outputBuffer,
    unsigned long framesPerBuffer,
    const PaStreamCallbackTimeInfo* timeInfo,
    PaStreamCallbackFlags statusFlags,
    void *userData)
{   printf("Being RecordCallBack *************** n");
    int finished;
    static int  totalRead = 0;
    (void)outputBuffer; 
    (void)timeInfo;
    (void)statusFlags;
    (void)userData;
    finished = paContinue;
    if (totalRead * NUM_CHANNELS * 2 > filesize)
    {
        sf_close(outfileCB);
        char * BUFF_Time;
        BUFF_Time = CurrentDateTime();
        char* s4=concat(FileNameHead,BUFF_Time);
        char* outfilename=concat(s4,".wav"); 
        free(s4);
        if (!(outfileCB = sf_open(outfilename, SFM_WRITE, &sfinfo)))
        {
            puts(sf_strerror(NULL));
            return  1;
        };
        sleep(1);
        copyString(wavefilename,outfilename);
        free(outfilename);
        totalRead = 0;
    } 
    int framesWritten = sf_writef_float(outfileCB, (const SAMPLE*)inputBuffer, framesPerBuffer);
    totalRead+= framesPerBuffer;
    return finished;
}
const char * CurrentDateTime()
{
    time_t raw_time;
    raw_time=time(NULL);
    static char strbuffer[16];
    strftime(strbuffer,16,"%m%d%Y_%H%M%S",localtime(&raw_time));
    return strbuffer;
}
char* concat(char *s1, char *s2)
{
    size_t len1 = strlen(s1);
    size_t len2 = strlen(s2);
    char *result = malloc(len1+len2+1);
    memcpy(result, s1, len1);
    memcpy(result+len1, s2, len2+1);
    return result;
}
int main(void);
int main(void)
{
    PaStreamParameters  inputParameters;
    PaStream*           stream;
    PaError             err = paNoError;
    paTestData          data;
    int                 i;
    int                 numSamples;
    int                 numBytes;
    int                 DeviceIdTarget;
    int             isfocusrite;
    printf("patest_record.cn"); fflush(stdout);
    config_t cfg;
    const char *EquipmentCC;
    const char *site;
    const char *area;
    filesize=0;
    NUM_CHANNELS=0;
    config_init(&cfg);
    if(! config_read_file(&cfg, "acoustic.cfg"))
    {
        fprintf(stderr, "%s:%d - %sn", config_error_file(&cfg),
        config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return(EXIT_FAILURE);
    }
    filesize=SAMPLE_RATE*NUM_CHANNELS*duration*2;
    copyString(equip,EquipmentCC);
    data.maxFrameIndex = FRAMES_PER_BUFFER;
    data.frameIndex = 0;
    numSamples = FRAMES_PER_BUFFER * NUM_CHANNELS;
    numBytes = numSamples * sizeof(SAMPLE);
    SAMPLE recordedSamplesArr[numBytes];
    // data.recordedSamples = recordedSamplesArr;
    data.recordedSamples = (SAMPLE *) malloc( numBytes ); 
    if( data.recordedSamples == NULL )
    {
        printf("Could not allocate record array.n");
        goto done;
    }
    for( i=0; i<numSamples; i++ ) data.recordedSamples[i] = 0;
    memset(&sfinfo, 0, sizeof(sfinfo));
    sfinfo.samplerate = SAMPLE_RATE;
    sfinfo.channels = NUM_CHANNELS;
    sfinfo.frames = 0;
    sfinfo.format = (SF_FORMAT_WAV | SF_FORMAT_PCM_16);
    char* Equipment=malloc(strlen(EquipmentCC)+1);
    strcpy(Equipment,EquipmentCC);
    char * BUFF_Time;
    BUFF_Time = CurrentDateTime();
    char* s1 = concat(site, "_");
    char* s2 = concat(s1,area);
    free(s1);
    char* s21 = concat(s2, "_");
    free(s2);
    char* s3=concat(s21,Equipment);
    free(s21);
    FileNameHead=concat(s3,"_");
    free(s3);
    char* s4=concat(FileNameHead,BUFF_Time);
    char* outfilename=concat(s4,".wav"); 
    copyString(wavefilename,outfilename);
    free(s4);
    config_destroy(&cfg);
    if (!(outfileCB = sf_open(outfilename, SFM_WRITE, &sfinfo)))
    {
        puts(sf_strerror(NULL));
        return  1;
    };
    free(outfilename);
    err = Pa_Initialize();
    if (err != paNoError) goto done;
    int numDevices =Pa_GetDeviceCount();
    if (numDevices < 0)
    {
        err = numDevices;
        goto done;
    }
    DeviceIdTarget=1;
    const   PaDeviceInfo *deviceInfo;
    const PaHostApiInfo *apiInfo;
    for (i = 0; i<numDevices; i++)
    {
        deviceInfo = Pa_GetDeviceInfo(i);
        apiInfo = Pa_GetHostApiInfo(deviceInfo->hostApi);
        isfocusrite=checkStringMatch((char *)deviceInfo->name, "Scarlett");
        if(isfocusrite&(deviceInfo->maxInputChannels>1)) DeviceIdTarget=i;
        if(deviceInfo->maxInputChannels==1) DeviceIdTarget=i;
    }   
    inputParameters.device = DeviceIdTarget; 
    if (inputParameters.device == paNoDevice) {
        goto done;
    }
    inputParameters.channelCount = NUM_CHANNELS;
    inputParameters.sampleFormat = PA_SAMPLE_TYPE;
    inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency;
    inputParameters.hostApiSpecificStreamInfo = NULL;
    err = Pa_OpenStream(
        &stream,
        &inputParameters,
        NULL,                
        SAMPLE_RATE,
        FRAMES_PER_BUFFER,
        paClipOff,
        recordCallback,
        &data);
    if (err != paNoError) goto done;

    err = Pa_StartStream(stream);
    if (err != paNoError) goto done;
    fflush(stdout);
    getchar();  
    err = Pa_CloseStream(stream);//
    if (err != paNoError) goto done;
    sf_close(outfileCB);
    free(FileNameHead);
    cleanup:
    free(data.recordedSamples);
    done:
    Pa_Terminate();
    if (err != paNoError)
    {
        err = 1;
    }
    return err;
    free(Equipment);
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật