【问题标题】:Android native process: stack corruption detectedAndroid 本机进程:检测到堆栈损坏
【发布时间】:2017-03-16 13:15:41
【问题描述】:

我正在增强一个本机应用程序,它已经是 Google 源代码的一部分。我看到了崩溃。我试过调试这个,但无法得出结论。非常感谢您的帮助:

struct device_global {
    struct support *sport;
    struct support_params params;
    struct global_priv *ctrl;

#if defined FEATURE_1
    int freq, freq_2;
#endif /* FEATURE_1 */

#ifdef FEATURE_2
    int wifi_display;
    #define SUBELEMS 10
    struct buf *subelem[MAX_SUBELEMS];
#endif /* FEATURE_2 */

    struct list_entry *add_list_entry;

#ifdef FEATURE_3
    void* my_context;
#endif /* FEATURE_3 */
};

typedef unsigned long       DWORD;
typedef DWORD           *PDWORD;

typedef struct
{
    DWORD dwFlags;
    DWORD dwErrorCode;
    DWORD dwDeviceId;

#ifdef FEATURE_X
    CHAR* tableFileName;
#endif

#ifdef FEATURE_Y
    FILE* tableFile;
    DWORD headerVersion;
    DWORD headerSize;
#endif
} CONTEXT1, *CONTEXT2;


struct device_global * init(struct support_params *params)
{
    struct device_global *global;
    global = os_malloc(sizeof(*global));
    if (params->ctrl)
            global->params.ctrl =  os_strdup(params->ctrl);
    // Assignment of other global variables done here like above (not added here to remove clutter)

    int deviceId = 0;
    if (0 == getDeviceId(global->my_context, (PDWORD) &deviceId))
    {
        printf("Device ID 0x%x", deviceId);
    }
    printf("Before returning global");    // gets printed before crash
    return global;   // crashes here
}



DWORD getDeviceId(PVOID pContext, PDWORD myDeviceId)
{
    CONTEXT2 myContext;

    if (!pContext || !myDeviceId)
    {
        return -1;
    }
    else
    {
        myContext = (CONTEXT2) pContext;
        *myDeviceId = myContext->dwDeviceId;
    }

    return 0;
}

崩溃恰好发生在“返回全局”的 init 方法中。 printf 语句被打印出来,然后崩溃出现。 请分享您的宝贵意见。

崩溃对应的错误信息是:

03-16 12:30:03.230  5626  5626 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
03-16 12:30:03.232  5626  5626 F DEBUG   : Abort message: 'stack corruption detected'

【问题讨论】:

  • 你在哪里为全局分配内存?
  • 问题已编辑。 malloc 在 'init' 方法中完成。
  • 现在结构中的每个指针都指向内存中的一些随机点。每次使用它们都会崩溃
  • int deviceId = 0;在问题中更新。
  • 来吧...您将为我们指出的每一件事进行编辑...提供mcve,因为现在我将投票赞成关闭作为题外话

标签: android c crash


【解决方案1】:

这里没有初始化my_context指针:

if (0 == getDeviceId(global->my_context, (PDWORD) &deviceId))    

因此,您的程序表现出未定义的行为,最终导致崩溃。

【讨论】:

    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2013-07-06
    相关资源
    最近更新 更多