简单的C / GTK +软件上的随机段错误

时间:2014-07-31 07:54:53

标签: c segmentation-fault gtk gtk3

我在main.c文件中有这个功能,它创建了一个由复选框和条目组成的简单对话框:

void compute_sha2 (GtkWidget *, struct hashWidget_t *);
void compute_sha3 (GtkWidget *, struct hashWidget_t *);
void compute_md5 (struct hashWidget_t *);
void compute_sha1 (struct hashWidget_t *);
void compute_gost94 (struct hashWidget_t *);
void compute_whirlpool (struct hashWidget_t *);


static void
compute_hash (  GtkWidget *fileDialog,
        GtkWidget *mainwin,
        const gchar *filename)
{
    gtk_widget_hide (GTK_WIDGET (fileDialog));

    struct hashWidget_t HashWidget;

    gsize lenFilename = g_utf8_strlen (filename, -1);

    HashWidget.filename = g_malloc (lenFilename + 1);
    if (HashWidget.filename == NULL)
    {
        g_printerr ("Error during memory allocation\n");
        return;
    }
    g_utf8_strncpy (HashWidget.filename, filename, lenFilename);
    HashWidget.filename[lenFilename] = '\0';

    gint i, result;
    const gchar *label[] = {"MD5", "SHA-1", "SHA-256", "SHA3-256", "SHA512", "SHA3-512", "WHIRLPOOL", "GOST94"};
    GtkWidget *contentArea, *grid, *dialog;
    GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;

    PangoFontDescription *newFont = pango_font_description_new ();
    pango_font_description_set_family (newFont, "monospace");

    dialog = gtk_dialog_new_with_buttons ("Select Hash",
                     GTK_WINDOW (mainwin),
                     flags,
                     _("Cancel"), GTK_RESPONSE_REJECT,
                     NULL);

    gtk_widget_set_size_request (dialog, 250, 150);

    contentArea = gtk_dialog_get_content_area (GTK_DIALOG (dialog));

    for (i = 0; i < NUM_OF_HASH; i++)
    {
        HashWidget.hashCheck[i] = gtk_check_button_new_with_label (label[i]);
        HashWidget.hashEntry[i] = gtk_entry_new ();
        gtk_editable_set_editable (GTK_EDITABLE (HashWidget.hashEntry[i]), FALSE);
        gtk_widget_override_font (GTK_WIDGET (HashWidget.hashEntry[i]), newFont);
    }

    pango_font_description_free (newFont);

    grid = gtk_grid_new ();
    gtk_grid_set_row_homogeneous (GTK_GRID (grid), TRUE);
    gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
    gtk_grid_set_row_spacing (GTK_GRID (grid), 5);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[0], 0, 0, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[0], 2, 0, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[1], 0, 1, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[1], 2, 1, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[2], 0, 2, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[2], 2, 2, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[3], 0, 3, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[3], 2, 3, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[4], 0, 4, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[4], 2, 4, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[5], 0, 5, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[5], 2, 5, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[6], 0, 6, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[6], 2, 6, 6, 1);

    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashCheck[7], 0, 7, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), HashWidget.hashEntry[7], 2, 7, 6, 1);

    gtk_container_add (GTK_CONTAINER (contentArea), grid);
    gtk_widget_show_all (dialog);

    gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[2]), "BtSha256");
    gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[3]), "BtSha3_256");
    gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[4]), "BtSha512");
    gtk_widget_set_name (GTK_WIDGET (HashWidget.hashCheck[5]), "BtSha3_512");

    g_signal_connect_swapped (HashWidget.hashCheck[0], "clicked", G_CALLBACK (compute_md5), &HashWidget);
    g_signal_connect_swapped (HashWidget.hashCheck[1], "clicked", G_CALLBACK (compute_sha1), &HashWidget);
    g_signal_connect (HashWidget.hashCheck[2], "clicked", G_CALLBACK (compute_sha2), &HashWidget);
    g_signal_connect (HashWidget.hashCheck[3], "clicked", G_CALLBACK (compute_sha3), &HashWidget);
    g_signal_connect (HashWidget.hashCheck[4], "clicked", G_CALLBACK (compute_sha2), &HashWidget);
    g_signal_connect (HashWidget.hashCheck[5], "clicked", G_CALLBACK (compute_sha3), &HashWidget);
    g_signal_connect_swapped (HashWidget.hashCheck[6], "clicked", G_CALLBACK (compute_whirlpool), &HashWidget);
    g_signal_connect_swapped (HashWidget.hashCheck[7], "clicked", G_CALLBACK (compute_gost94), &HashWidget);

    result = gtk_dialog_run (GTK_DIALOG (dialog));
    switch (result)
    {
        case GTK_RESPONSE_REJECT:
            g_free (HashWidget.filename);
            gtk_widget_destroy (dialog);
            break;
    }
}

compute_*函数具有相同的代码库(sha2和sha3除外,它们具有256/512开关的情况):

static goffset get_file_size (const gchar *);

void
compute_sha3 (  GtkWidget *checkBt,
        struct hashWidget_t *HashWidget)
{
    gint bit;

    if (g_strcmp0 (gtk_widget_get_name (checkBt), "BtSha3_256") == 0)
        bit = 256;
    else if (g_strcmp0 (gtk_widget_get_name (checkBt), "BtSha3_512") == 0)
        bit = 512;

    if (bit == 256)
    {
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (HashWidget->hashCheck[3])))
        {
            gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[3]), "");
            goto fine;
        }
        else if (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (HashWidget->hashEntry[3])), -1) == 64)
            goto fine;
    }
    else
    {
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (HashWidget->hashCheck[5])))
        {
            gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[5]), "");
            goto fine;
        }
        else if (g_utf8_strlen (gtk_entry_get_text (GTK_ENTRY (HashWidget->hashEntry[5])), -1) == 128)
            goto fine;      
    }

    guchar *digest;
    gchar *hash;
    GError *err = NULL;
    gint fd, i, retVal;
    goffset fileSize, doneSize = 0, diff = 0, offset = 0;
    guint8 *fAddr;

    struct sha3_256_ctx ctx256;
    struct sha3_512_ctx ctx512;

    if (bit == 256)
    {
        digest = g_malloc (SHA3_256_DIGEST_SIZE);
        hash = g_malloc (65);
    }

    else
    {
        digest = g_malloc (SHA3_512_DIGEST_SIZE);
        hash = g_malloc (129);
    }

    if (digest == NULL)
    {
        g_printerr ("sha2: error during memory allocation\n");
        return;
    }

    if (hash == NULL)
    {
        g_printerr ("sha2: error during memory allocation\n");
        g_free (digest);
        return;
    }

    fd = g_open (HashWidget->filename, O_RDONLY | O_NOFOLLOW);
    if (fd == -1)
    {
        g_printerr ("sha2: %s\n", g_strerror (errno));
        return;
    }

    fileSize = get_file_size (HashWidget->filename);

    if (bit == 256)
        sha3_256_init (&ctx256);
    else
        sha3_512_init (&ctx512);

    if (fileSize < BUF_FILE)
    {
        fAddr = mmap (NULL, fileSize, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0);
        if (fAddr == MAP_FAILED)
        {
            g_printerr ("sha2: %s\n", g_strerror (errno));
            g_free (digest);
            g_free (hash);
            g_close (fd, &err);
            return;
        }
        if (bit == 256)
            sha3_256_update (&ctx256, fileSize, fAddr);
        else
            sha3_512_update (&ctx512, fileSize, fAddr);

        retVal = munmap (fAddr, fileSize);
        if (retVal == -1)
        {
            g_printerr ("sha2: %s\n", g_strerror (errno));
            g_free (digest);
            g_free (hash);
            g_close (fd, &err);
            return;
        }
        goto nowhile;
    }

    while (fileSize > doneSize)
    {
        fAddr = mmap (NULL, BUF_FILE, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
        if (fAddr == MAP_FAILED)
        {
            g_printerr ("sha2: %s\n", g_strerror (errno));
            g_free (digest);
            g_free (hash);
            g_close (fd, &err);
            return;
        }

        if (bit == 256)
            sha3_256_update(&ctx256, BUF_FILE, fAddr);
        else
            sha3_512_update(&ctx512, BUF_FILE, fAddr);

        doneSize += BUF_FILE;
        diff = fileSize - doneSize;
        offset += BUF_FILE;

        if (diff < BUF_FILE && diff > 0)
        {
            fAddr = mmap (NULL, diff, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);
            if (fAddr == MAP_FAILED)
            {
                g_printerr ("sha2: %s\n", g_strerror (errno));
                g_free (digest);
                g_free (hash);
                g_close (fd, &err);
                return;
            }

            if (bit == 256)
                sha3_256_update(&ctx256, diff, fAddr);
            else
                sha3_512_update(&ctx512, diff, fAddr);

            retVal = munmap(fAddr, BUF_FILE);
            if(retVal == -1){
                g_printerr ("sha2: %s\n", g_strerror (errno));
                g_free (digest);
                g_free (hash);
                g_close (fd, &err);
                return;
            }
            break;
        }

        retVal = munmap(fAddr, BUF_FILE);
        if(retVal == -1)
        {
            g_printerr ("sha2: %s\n", g_strerror (errno));
            g_free (digest);
            g_free (hash);
            g_close (fd, &err);
            return;
        }
    }

    nowhile:
    if (bit == 256)
    {
        sha3_256_digest(&ctx256, SHA3_256_DIGEST_SIZE, digest);
        for(i=0; i<32; i++)
            g_sprintf (hash+(i*2), "%02x", digest[i]);

        hash[64] = '\0';
        gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[3]), hash);        
    }
    else
    {
        sha3_512_digest(&ctx512, SHA3_512_DIGEST_SIZE, digest);
        for(i=0; i<64; i++)
            g_sprintf (hash+(i*2), "%02x", digest[i]);

        hash[128] = '\0';
        gtk_entry_set_text (GTK_ENTRY (HashWidget->hashEntry[5]), hash);        
    }

    g_close (fd, &err);
    g_free (digest);
    g_free (hash);

    fine:
    return;
}


static goffset
get_file_size (const gchar *filePath)
{
    GFileInfo *info;
    GFile *file;
    GError *error = NULL;
    const gchar *attributes = "standard::*";
    GFileQueryInfoFlags flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
    GCancellable *cancellable = NULL;
    goffset fileSize;

    file = g_file_new_for_path (filePath);
    info = g_file_query_info (file, attributes, flags, cancellable, &error);
    fileSize = g_file_info_get_size (info);

    g_object_unref(file);

    return fileSize;
}

问题在于,当我尝试计算哈希时,我得到了一个段错误(低于3段错误的输出):

polcrypt[1678]: segfault at 7f48a40018d8 ip 00007f48e0ae9e8d sp 00007fff2ce02230 error 4 in libgtk-3.so.0.1200.2[7f48e08ac000+51a000]
gmain[1883]: segfault at 7f8814001b38 ip 00007f885f2a7f8b sp 00007f884ab1fc70 error 6 in libglib-2.0.so.0.4000.0[7f885f262000+130000]
polcrypt[1941]: segfault at 7f885c001b18 ip 00007f88868d045f sp 00007fffa35ddc60 error 7 in libglib-2.0.so.0.4000.0[7f888686c000+130000

有时我在1次计算后得到了段错误,有时候在3次之后等等,但我注意到只有在选择了大于10M的文件时才会发生段错误。

我认为问题出在main.c文件中,因为如果我在g_print函数的末尾添加compute_*,则在获取段错误之前会在屏幕上打印print语句

我使用GNOME 3.12,Glib 2.40,GCC 4.8和libc-2.19开发Gentoo~x64和Fedora 20

编辑(核心转储):

Reading symbols from polcrypt...(no debugging symbols found)...done.
[New LWP 8848]
[New LWP 8849]
[New LWP 8850]
[New LWP 8853]

warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `./polcrypt'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f38888fada7 in g_slice_alloc () from /usr/lib64/libglib-2.0.so.0

然后是完整的bt:

(gdb) bt full
#0  0x00007f38888fada7 in g_slice_alloc () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#1  0x00007f38888b4d35 in g_array_sized_new () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#2  0x00007f388a4d181f in gtk_widget_path_new () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#3  0x00007f388a4cdc76 in _gtk_widget_create_path () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#4  0x00007f388a2f2820 in gtk_container_real_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#5  0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#6  0x00007f388a2b265d in gtk_box_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#7  0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#8  0x00007f388a2f2820 in gtk_container_real_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#9  0x00007f388a2f7cb7 in gtk_container_get_path_for_child () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#10 0x00007f388a4cdc0d in gtk_widget_get_path () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#11 0x00007f388016d100 in adwaita_engine_render_focus () from /usr/lib64/gtk-3.0/3.0.0/theming-engines/libadwaita.so
No symbol table info available.
#12 0x00007f388a4293e1 in gtk_render_focus () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#13 0x00007f388a2e076c in gtk_check_button_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#14 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#15 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#16 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#17 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#18 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#19 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#20 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#21 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#22 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#23 0x00007f388a3570a2 in gtk_grid_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#24 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#25 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#26 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#27 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#28 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#29 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#30 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#31 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#32 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#33 0x00007f388a2b4882 in gtk_box_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#34 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#35 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#36 0x00007f3888bda53f in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#37 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#38 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#39 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#40 0x00007f388a4cc6eb in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#41 0x00007f388a2f7abd in gtk_container_propagate_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#42 0x00007f388a2f7b82 in gtk_container_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#43 0x00007f388a4dd4a4 in gtk_window_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#44 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#45 0x00007f388a4bd4dd in gtk_widget_draw_marshallerv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#46 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#47 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#48 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#49 0x00007f388a4cad16 in _gtk_widget_draw_internal.part.62 () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#50 0x00007f388a4cc35f in _gtk_widget_draw_windows () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#51 0x00007f388a4cc5af in _gtk_widget_draw () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#52 0x00007f388a4cc903 in gtk_widget_send_expose () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#53 0x00007f388a392435 in gtk_main_do_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#54 0x00007f3889f8414b in _gdk_window_process_updates_recurse_helper () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#55 0x00007f3889f82545 in gdk_window_process_updates_internal () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#56 0x00007f3889f8266f in gdk_window_process_updates_with_mode () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#57 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#58 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#59 0x00007f3888bf4132 in g_signal_emit_by_name () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#60 0x00007f3889f7c8b0 in gdk_frame_clock_paint_idle () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#61 0x00007f3889f6ee68 in gdk_threads_dispatch () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#62 0x00007f38888e0283 in g_timeout_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#63 0x00007f38888df865 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#64 0x00007f38888dfbc8 in g_main_context_iterate.isra () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#65 0x00007f38888dfe8a in g_main_loop_run () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#66 0x00007f388a31a230 in gtk_dialog_run () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#67 0x000000000040a0be in compute_hash ()
No symbol table info available.
#68 0x000000000040871d in choose_file ()
No symbol table info available.
#69 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#70 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#71 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#72 0x00007f388a2bfacd in gtk_button_do_release () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#73 0x00007f388a2bfb13 in gtk_real_button_released () from /usr/lib64/libgtk-3.so.0
---Type <return> to continue, or q <return> to quit---
No symbol table info available.
#74 0x00007f3888bda398 in g_closure_invoke () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#75 0x00007f3888beb467 in signal_emit_unlocked_R () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#76 0x00007f3888bf3939 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#77 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#78 0x00007f388a2bea31 in gtk_button_button_release () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#79 0x00007f388a392ebe in _gtk_marshal_BOOLEAN__BOXEDv () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#80 0x00007f3888bda5c7 in _g_closure_invoke_va () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#81 0x00007f3888bf2f98 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#82 0x00007f3888bf3bfa in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0
No symbol table info available.
#83 0x00007f388a4c0b54 in gtk_widget_event_internal () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
---Type <return> to continue, or q <return> to quit---
#84 0x00007f388a39093c in propagate_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#85 0x00007f388a3923b5 in gtk_main_do_event () from /usr/lib64/libgtk-3.so.0
No symbol table info available.
#86 0x00007f3889f9cc72 in gdk_event_source_dispatch () from /usr/lib64/libgdk-3.so.0
No symbol table info available.
#87 0x00007f38888df984 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#88 0x00007f38888dfbc8 in g_main_context_iterate.isra () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#89 0x00007f38888dfc6c in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
No symbol table info available.
#90 0x00007f3888ebe0ec in g_application_run () from /usr/lib64/libgio-2.0.so.0
No symbol table info available.
#91 0x00000000004082ff in main ()
No symbol table info available.

1 个答案:

答案 0 :(得分:0)

发现问题! 此代码段中的munmap函数必须以diff作为长度arg,而不是BUF_FILE

   if (diff < BUF_FILE && diff > 0)
    {
        fAddr = mmap (NULL, diff, PROT_READ, MAP_FILE | MAP_SHARED, fd, offset);

        retVal = munmap(fAddr, BUF_FILE); //wrong

        retVal = munmap(fAddr, diff); //correct

        break;
    }