使用 MySQL/Connector C 库的 C 应用程序消耗内存非常快

问题描述

我很高兴在我的 C 应用程序中使用 MysqL/Connector C 库来操作数据库。然而,使用该应用程序会导致大量内存使用,事实上我不得不考虑使用 systemd 来管理该应用程序,我假设该应用程序将在启动时作为服务运行,因为它需要始终处于活动状态.我不想进一步混淆/增加复杂性,而是想解决应用程序中的问题。

  • 系统:树莓派 4B
  • 操作系统:Raspbian Buster
  • sql 库:mariadb-connector-c-3.1.7
  • 数据库:MariaDB 10.3.22 服务器,本地 托管

我通常使用 MysqL_free_result(sqlRes) 清除将结果集存储到我的 MysqL_RES 对象的查询。插入我保持相当简单。从功能的角度来看,一切都正常工作,但它的内存消耗简直是天翻地覆。我假设其中很多是由于我在 main() 循环代码中的等待时间造成的,但我希望能够以非阻塞方式与以 115.2k 通信的主机系统监视 UART 连接。

是否有我偏离路线的最佳实践?我的许多初始代码的开发类似于 here 概述的代码。我没有在 Raspbian 中使用任何内存分析应用程序,因为我对它们不太熟悉。

谢谢

// MysqL/Connector C API objects for database management

MysqL *connect;                 // MysqL object for managing connection
MysqL_RES *sqlRes;              // When querying a results set,use this object to store them
MysqL_ROW sqlRow;               // When iterating through results,use this object to store each
MysqL_FIELD *sqlFields;
int MysqL_query_status=0;
my_ulonglong numRows;
unsigned int numFields;

int insert_t_data(char* id,char* level,char* di)
{

 // Insert data records into database
    int strret = snprintf(insertString,103,"INSERT INTO t_data (id,value_type,value) VALUES ('%s','%s','%s');",id,di,level);

    MysqL_query_status = MysqL_query(connect,insertString);
    if (MysqL_query_status)
    {
        printf("MysqL error at Insert into t_data: %s",MysqL_error(connect));
        errchk++;
        return 1;
    }

    return 0;
}

int update_tank(char* id,uint8_t sh,uint8_t sl,uint8_t ts,uint8_t alarms_anc)
{
    uint8_t hf = (alarms_anc >> 1) & 1U;

    // Insert t_data records into database
    int strret = snprintf(insertString,100,"SELECT * FROM t WHERE description='%s' ORDER BY timestamp DESC LIMIT 1;",id);

    if ((MysqL_query_status=MysqL_query(connect,insertString)))      // Error in query
    {
        printf("Couldn't find existing record. Inserting new record to 't' for '%s'",id);
    }
    else      // Successful query (but not necessarily any rows)
    {
        sqlRes = MysqL_store_result(connect);     // Retrieve the resulting set from this query
        numRows = MysqL_num_rows(sqlRes);
        if ((sqlRes) && (numRows))
        {
            // Record already exists,proceed to update.
            MysqL_free_result(sqlRes);
        }
        else
        {
            // Create a row since it wasn't there,proceed to update.
            strret = snprintf(insertString,75,"INSERT INTO t (r_id,description) VALUES ('%d',4digit,id);

            MysqL_query_status = MysqL_query(connect,insertString);
            if (MysqL_query_status)
            {
                printf("MysqL error at t: %s",MysqL_error(connect));
                errchk++;
            }
        }
    }

    strret = snprintf(insertString,150,"UPDATE t SET high='%d',low='%d',height='%d',h='%d' WHERE description='%s'",sh,sl,ts,hf,id);

    MysqL_query_status = MysqL_query(connect,insertString);
    if (MysqL_query_status)
    {
        printf("MysqL error at t_data: %s",MysqL_error(connect));
        errchk++;
        return 1;
    }

    return 0;
}

void db_connect(void)
{
    printf("Reached DB Connect.\n");
    connect = MysqL_init(NULL);
    connect = MysqL_real_connect(connect,SERVER,USER,PASSWORD,DATABASE,NULL,0);
    if ((!connect) || (connect == NULL))
    {
        printf("MysqL Failed to initialize. Connection to 'db' Failed.\n");
        errchk=1;           // Use errchk throughout for reconnect
    }
    else
    {
        printf("Connection successful.\n");
    }

}


int main(void)
{
    
    usleep(5000);                        // Slight delay at startup
    memset(&rbuf,'\0',sizeof(rbuf));   // Clear read buffer before communication
    bufptr=rbuf;

    db_connect();

// LOOP section ---------------

    while(TRUE)
    {
        // 1.) Read serial port for real-time updates
        // 2.) Write sql data resulting from any updates
        // 3.) Read sql tables for any user actions/updates
        // 4.) Write serial actions/cmds

        if (errchk > 10) {
            MysqL_close(connect);
            sleep(10);
            errchk=0;
            db_connect();
        }

        usleep(100000); // Wait 100ms - This setting consumes 0.1% memory every 50 sec
        // usleep(10000);  // Wait 10 ms - Ideal - This setting consumes 0.1% memory every 10 sec 

        check_uart();   // This is a function that can trigger sql inserts/updates

        // if new data detected,then...
        insert_t_data(id,level,di); 
        // if new updates needed,then...
        update_tank(id,size,alarms);

    }

    close(serial_port);
    MysqL_close(connect);
}


编辑 1:Valgrind 日志异常

pi@raspBerrypi:~/beehive/bin/Debug $ valgrind --leak-check=yes ./beehive
==6693== Memcheck,a memory error detector
==6693== copyright (C) 2002-2011,and GNU GPL'd,by Julian Seward et al.
==6693== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==6693== Command: ./beehive
==6693== 
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/ld-2.28.so:
--6693-- Ignoring non-Dwarf2/3/4 block in .debug_info
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/ld-2.28.so:
--6693-- Last block truncated in .debug_info; ignoring
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401A5D0: index (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401A5D4: index (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4008040: _dl_dst_count (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4008288: expand_dynamic_string_token (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401AA80: strlen (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401AA84: strlen (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4017F68: malloc (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4017F74: malloc (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B5E8: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B608: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B618: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B634: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B63C: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B664: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B664: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B68C: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6A0: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6A4: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6B0: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x40180A4: calloc (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4017FA8: malloc (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401A160: mmap (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Syscall param mmap2(start) contains uninitialised byte(s)
==6693==    at 0x401A174: mmap (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Syscall param mmap2(length) contains uninitialised byte(s)
==6693==    at 0x401A174: mmap (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Syscall param mmap2(offset) contains uninitialised byte(s)
==6693==    at 0x401A174: mmap (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4017F44: malloc (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x400BDD0: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B5F4: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B630: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BD7C: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BD98: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401AA14: strdup (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B660: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B660: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B688: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4008E20: _dl_map_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Syscall param openat(filename) contains uninitialised byte(s)
==6693==    at 0x4019F4C: __open64_nocancel (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x40180E4: free (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x400BB84: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BB9C: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BBBC: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BBC0: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BBE0: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BC50: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BC64: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BCA8: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BCC0: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401AA30: strlen (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401AA48: strlen (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B628: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400BD9C: _dl_new_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4005D98: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005DC4: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005DD0: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005E50: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005E9C: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005EA0: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400602C: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x40060C0: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x40060DC: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4006114: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4006A0C: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x40061D4: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4010FF4: _dl_name_match_p (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4011008: _dl_name_match_p (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401A620: strcmp (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4010FFC: _dl_name_match_p (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x4013660: _dl_get_origin (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B680: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B684: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B690: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B694: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6B0: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6B4: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4013674: _dl_get_origin (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x400832C: expand_dynamic_string_token (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x40082E4: expand_dynamic_string_token (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4008114: _dl_dst_substitute (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401A67C: strcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4008198: _dl_dst_substitute (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6A8: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6AC: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B6B4: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x400926C: _dl_map_object (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B7A0: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6AC: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B658: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B65C: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B668: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B66C: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B658: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B850: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6A0: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6A4: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B6A8: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005FE0: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x4006020: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B648: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x401B900: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/libm-2.28.so:
--6693-- Ignoring non-Dwarf2/3/4 block in .debug_info
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/libm-2.28.so:
--6693-- Last block truncated in .debug_info; ignoring
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B66C: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== 
==6693== More than 100 errors detected.  Subsequent errors
==6693== will still be recorded,but in less detail than before.
==6693== Use of uninitialised value of size 4
==6693==    at 0x4005FCC: _dl_map_object_from_fd (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/libc-2.28.so:
--6693-- Ignoring non-Dwarf2/3/4 block in .debug_info
--6693-- WARNING: SerIoUs error when reading debug info
--6693-- When reading debug info from /lib/arm-linux-gnueabihf/libc-2.28.so:
--6693-- Last block truncated in .debug_info; ignoring
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x400E3FC: _dl_map_object_deps (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Use of uninitialised value of size 4
==6693==    at 0x400E410: _dl_map_object_deps (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 
==6693== Conditional jump or move depends on uninitialised value(s)
==6693==    at 0x401B668: memcpy (in /lib/arm-linux-gnueabihf/ld-2.28.so)
==6693== 

解决方法

mysql_free_result 需要发生在 (sqlRes) && !(numRows)