Random segfaults on a simple C/GTK+ software - c

I have this function inside the main.c file which create a simple dialog made of check boxes and entries:
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;
}
}
The compute_* functions have the same codebase (except for sha2 and sha3 which have a 256/512 switch case):
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;
}
The problem is that i'm getting a segfault when i'm trying to compute hashes (below there is the output of 3 segfault):
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
Sometimes i got the segfault after 1 computation, sometimes after 3 and so on but what i have noticed is that the segfault occurs only when a file bigger than 10M is selected.
I think the problem is inside the main.c file because if i put a g_print at the end of the compute_* functions, the print statement is printed on the screen before getting the segfault.
I'm developing on Gentoo ~x64 and Fedora 20 both with GNOME 3.12, Glib 2.40, GCC 4.8 and libc-2.19
EDIT (core dump):
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
and then the full 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.

Problem found!
The munmap function in this snippet must take diff as length arg and not 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;
}

Related

How to copy portion of char buffer into char[]?

I'm trying to read the process name from /proc/[pid]/stat and that is mostly successful. Yet valgrind complains about something, and the process crashes after some time. My code comes from procps-ng with a few modifications. What I've attempted to do is read the file into a buffer, then find a pointer to the start and end of the process name in that buffer. After that strncpy copies the selected section into the destination buffer and then I add null to the end.
Is this the wrong approach?
The relevant bit of code is here:
rc = file2str(path,"stat", &ub);
if (rc <= 0) return rc;
ub.buf = strchr(ub.buf, '(');
if (!ub.buf) return 0;
ub.buf++;
tmp = strrchr(ub.buf, ')');
if (!tmp || !tmp[1]) return 0;
strncpy(name, ub.buf, (tmp - ub.buf));
name[tmp - ub.buf + 1] = 0;
return (tmp - ub.buf);
The same file2str function is called from another place where it works reliably. I've tried to invoke it in the same way, so I am at a loss for why it fails here.
Valgrind says:
Syscall param read(buf) points to unaddressable byte(s)
at 0x4C4A912: read (read.c:26)
by 0x10D2F9: read (unistd.h:47)
by 0x10D2F9: file2str (procs.c:98)
by 0x10D6B0: stat2name (procs.c:159)
by 0x10DEAA: walk_and_draw (pidgrid.c:313)
by 0x4C55D72: trecurse_r (tsearch.c:739)
by 0x4C55D62: trecurse_r (tsearch.c:736)
by 0x4C55D62: trecurse_r (tsearch.c:736)
by 0x4C55D62: trecurse_r (tsearch.c:736)
by 0x4C55D62: trecurse_r (tsearch.c:736)
by 0x4C55D72: trecurse_r (tsearch.c:739)
by 0x4C55D72: trecurse_r (tsearch.c:739)
by 0x4C56B92: trecurse_r (tsearch.c:736)
by 0x4C56B92: twalk_r (tsearch.c:753)
Full code listing can be found here: https://github.com/robbieh/xscreensaver-pidgrid
edit #1
The var name gets filled. In this case with "Isolated Web Co". That gets written into text which contains "PID: 1737571 UID: 1000 RSS: 83241 VSIZE: 3037233152 STATE: S OOMSCORE: 670 -- Isolated Web Co".
Here's what I get out of GDB:
#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=140737346060608) at pthread_kill.c:44
#1 __pthread_kill_internal (signo=6, threadid=140737346060608) at pthread_kill.c:80
#2 __GI___pthread_kill (threadid=140737346060608, signo=signo#entry=6) at pthread_kill.c:91
#3 0x00007ffff7b03476 in __GI_raise (sig=sig#entry=6) at ../sysdeps/posix/raise.c:26
#4 0x00007ffff7ae97b7 in __GI_abort () at abort.c:79
#5 0x00007ffff7b4a5e6 in __libc_message (action=action#entry=do_abort, fmt=fmt#entry=0x7ffff7c9c13d "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#6 0x00007ffff7b61adc in malloc_printerr (str=str#entry=0x7ffff7c99e4b "realloc(): invalid old size") at malloc.c:5543
#7 0x00007ffff7b65534 in _int_realloc (av=av#entry=0x7ffff7cd5c60 <main_arena>, oldp=oldp#entry=0x555555cd1680, oldsize=<optimized out>, nb=nb#entry=1040) at malloc.c:4718
#8 0x00007ffff7b66149 in __GI___libc_realloc (oldmem=0x555555cd1690, bytes=1024) at malloc.c:3372
#9 0x00007ffff79c565f in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#10 0x00007ffff79c56be in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#11 0x00007ffff79c585c in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#12 0x00007ffff79d370e in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#13 0x00007ffff79da544 in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#14 0x00007ffff79dff6f in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#15 0x00007ffff79c4c88 in FT_Load_Glyph () from /lib/x86_64-linux-gnu/libfreetype.so.6
#16 0x00007ffff7a1371b in ?? () from /lib/x86_64-linux-gnu/libfreetype.so.6
#17 0x00007ffff79c5161 in FT_Load_Glyph () from /lib/x86_64-linux-gnu/libfreetype.so.6
#18 0x00007ffff7f941aa in XftFontLoadGlyphs () from /lib/x86_64-linux-gnu/libXft.so.2
#19 0x00007ffff7f990f3 in XftGlyphRender () from /lib/x86_64-linux-gnu/libXft.so.2
#20 0x00007ffff7f99333 in XftDrawGlyphs () from /lib/x86_64-linux-gnu/libXft.so.2
#21 0x00007ffff7f9994b in XftDrawStringUtf8 () from /lib/x86_64-linux-gnu/libXft.so.2
#22 0x0000555555559f97 in walk_and_draw (what=<optimized out>, which=<optimized out>, closure=0x555555592040) at pidgrid.c:326
#23 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555bbb790, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#24 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555bb5fb0, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#25 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555baaff0, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#26 0x00007ffff7bdfd63 in trecurse_r (vroot=0x555555bc0f70, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:736
#27 0x00007ffff7bdfd63 in trecurse_r (vroot=0x555555bece70, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:736
#28 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555b95070, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#29 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555ae5470, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#30 0x00007ffff7bdfd73 in trecurse_r (vroot=0x555555a35870, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:739
#31 0x00007ffff7be0b83 in trecurse_r (closure=0x555555592040, action=0x5555555597b0 <walk_and_draw>, vroot=0x5555555a9b60) at tsearch.c:739
#32 __GI___twalk_r (vroot=0x5555555a9b60, action=0x5555555597b0 <walk_and_draw>, closure=0x555555592040) at tsearch.c:753
#33 0x000055555555a35b in pidgrid_draw (dpy=<optimized out>, window=<optimized out>, closure=0x555555592040) at pidgrid.c:616
#34 0x00005555555586ef in run_screenhack_table (ft=<optimized out>, window2=<optimized out>, window=<optimized out>, dpy=<optimized out>) at screenhack.c:593
#35 main (argc=<optimized out>, argv=<optimized out>) at screenhack.c:996

Segmentation fault occurred when providing incorrect HTTP_PROXY_OPTIONS in azure iot sdk c

I am developing a small application that uses the azure iot sdk in C (lts_07_2021). All my test cases worked well except for one that is related to the proxy. When providing a working/correct proxy server information, my application successfully connected without any problems. But when I provided a non-working proxy information, it produces a segfault. I expected that the SDK will provide some sort of error message but not the segfault.
It can also be reproduced using the example provided by azure in azure-iot-sdk-c/iothub_client/samples/iothub_ll_telemetry_sample
I just added the following options:
HTTP_PROXY_OPTIONS proxy;
memset(&proxy, 0, sizeof(HTTP_PROXY_OPTIONS));
proxy.host_address = "x.x.x.x"; //non-working proxy server
proxy.port = 3128;
(void)IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_HTTP_PROXY,&proxy);
Heres the terminal output when running iothub_ll_telemetry_sample provided by azure + INCORRECT PROXY:
https://github.com/Azure/azure-iot-sdk-c/blob/lts_07_2021/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c
[iothub_ll_telemetry_sample]$ ./iothub_ll_telemetry_sample
Creating IoTHub Device handle
Sending message 1 to IoTHub
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/adapters/socketio_berkeley.c Func:wait_for_connection Line:415 Failure: select failure.
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/adapters/socketio_berkeley.c Func:socketio_open Line:833 wait_for_connection failed
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/src/http_proxy_io.c Func:on_underlying_io_open_complete Line:280 Underlying IO open failed
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:onOpenComplete Line:454 Error: failure opening connection to endpoint
The device client has been disconnected
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/adapters/tlsio_openssl.c Func:on_underlying_io_open_complete Line:849 Invalid tlsio_state. Expected state is TLSIO_STATE_OPENING_UNDERLYING_IO.
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/src/http_proxy_io.c Func:http_proxy_io_open Line:749 Cannot open the underlying IO.
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/adapters/tlsio_openssl.c Func:tlsio_openssl_open Line:1437 Failed opening the underlying I/O.
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/src/uws_client.c Func:uws_client_open_async Line:1700 Opening the underlying IO failed
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/c-utility/src/wsio.c Func:wsio_open Line:519 Opening the uws instance failed.
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/umqtt/src/mqtt_client.c Func:mqtt_client_connect Line:1118 Error: io_open failed
Error: Time:Tue Feb 8 13:14:51 2022 File:/isolated/azure-iot-sdk-c/iothub_client/src/iothubtransport_mqtt_common.c Func:SendMqttConnectMsg Line:2696 failure connecting to address xxxxxxxxxx.azure-devices.net.
Sending message 2 to IoTHub
Segmentation fault (core dumped)
Here's the backtrace:
It seems like the stack frames goes on and on... repeating
#0 0x00000000004383c7 in OptionHandler_Destroy ()
#1 0x00000000004403c1 in http_proxy_io_destroy_option ()
#2 0x0000000000437ea3 in DestroyInternal ()
#3 0x00000000004383cc in OptionHandler_Destroy ()
#4 0x00000000004403c1 in http_proxy_io_destroy_option ()
#5 0x0000000000437ea3 in DestroyInternal ()
#6 0x00000000004383cc in OptionHandler_Destroy ()
#7 0x00000000004403c1 in http_proxy_io_destroy_option ()
#8 0x0000000000437ea3 in DestroyInternal ()
#9 0x00000000004383cc in OptionHandler_Destroy ()
#10 0x00000000004403c1 in http_proxy_io_destroy_option ()
#11 0x0000000000437ea3 in DestroyInternal ()
#12 0x00000000004383cc in OptionHandler_Destroy ()
#13 0x00000000004403c1 in http_proxy_io_destroy_option ()
#14 0x0000000000437ea3 in DestroyInternal ()
#15 0x00000000004383cc in OptionHandler_Destroy ()
#16 0x00000000004403c1 in http_proxy_io_destroy_option ()
#17 0x0000000000437ea3 in DestroyInternal ()
#18 0x00000000004383cc in OptionHandler_Destroy ()
#19 0x00000000004403c1 in http_proxy_io_destroy_option ()
#20 0x0000000000437ea3 in DestroyInternal ()
#21 0x00000000004383cc in OptionHandler_Destroy ()
#22 0x00000000004403c1 in http_proxy_io_destroy_option ()
#23 0x0000000000437ea3 in DestroyInternal ()
#24 0x00000000004383cc in OptionHandler_Destroy ()
#25 0x00000000004403c1 in http_proxy_io_destroy_option ()
#26 0x0000000000437ea3 in DestroyInternal ()
#27 0x00000000004383cc in OptionHandler_Destroy ()
#28 0x00000000004403c1 in http_proxy_io_destroy_option ()
#29 0x0000000000437ea3 in DestroyInternal ()
#30 0x00000000004383cc in OptionHandler_Destroy ()
#31 0x00000000004403c1 in http_proxy_io_destroy_option ()
#32 0x0000000000437ea3 in DestroyInternal ()
#33 0x00000000004383cc in OptionHandler_Destroy ()
#34 0x00000000004403c1 in http_proxy_io_destroy_option ()
#35 0x0000000000437ea3 in DestroyInternal ()
#36 0x00000000004383cc in OptionHandler_Destroy ()
#37 0x00000000004403c1 in http_proxy_io_destroy_option ()
#38 0x0000000000437ea3 in DestroyInternal ()
#39 0x00000000004383cc in OptionHandler_Destroy ()
#40 0x00000000004403c1 in http_proxy_io_destroy_option ()
#41 0x0000000000437ea3 in DestroyInternal ()
#42 0x00000000004383cc in OptionHandler_Destroy ()
#43 0x00000000004403c1 in http_proxy_io_destroy_option ()
#44 0x0000000000437ea3 in DestroyInternal ()
#45 0x00000000004383cc in OptionHandler_Destroy ()
#46 0x00000000004403c1 in http_proxy_io_destroy_option ()
#47 0x0000000000437ea3 in DestroyInternal ()
#48 0x00000000004383cc in OptionHandler_Destroy ()
#49 0x00000000004403c1 in http_proxy_io_destroy_option ()
#50 0x0000000000437ea3 in DestroyInternal ()
#51 0x00000000004383cc in OptionHandler_Destroy ()
#52 0x00000000004403c1 in http_proxy_io_destroy_option ()
#53 0x0000000000437ea3 in DestroyInternal ()
#54 0x00000000004383cc in OptionHandler_Destroy ()
#55 0x00000000004403c1 in http_proxy_io_destroy_option ()
.
.
.
.
.
.#xxxxx repeatedly goes on and on
System information:
CentOS-7
cURL7.29
openssl1.0.2k
This issue was fixed by https://github.com/Azure/azure-c-shared-utility/commit/2d74785c2b475ca94321114a23f8007094bdac11
Updating to the latest lts_01_2022 solved this problem.
Thanks!

delete database when log out and create again after log in dart

I am developing an app in Flutter and dart , using SQFLite database and Firestore , I want when the user click on logout button , app deletes the sqflite database and return the user to Log In Screen and when Log In fetch the data user info log in from Firestore ,and it deletes the DB , but the problem is when I want to log in again to app , it shows me this error ..
Please need help
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(database_closed 1)
#0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:12:7)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #1 SqfliteDatabaseFactoryImpl.wrapDatabaseException
(package:sqflite/src/factory_impl.dart:25:7)
E/flutter (28706): #2 SqfliteDatabaseMixin.safeInvokeMethod
(package:sqflite/src/database_mixin.dart:188:15)
E/flutter (28706): #3 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure>
(package:sqflite/src/database_mixin.dart:363:14)
E/flutter (28706): #4 SqfliteDatabaseMixin.txnSynchronized.<anonymous closure>
(package:sqflite/src/database_mixin.dart:307:22)
E/flutter (28706): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:32:26)
E/flutter (28706): #6 SqfliteDatabaseMixin.txnSynchronized
(package:sqflite/src/database_mixin.dart:303:43)
E/flutter (28706): #7 SqfliteDatabaseMixin.txnWriteSynchronized
(package:sqflite/src/database_mixin.dart:325:7)
E/flutter (28706): #8 SqfliteDatabaseMixin.txnRawInsert
(package:sqflite/src/database_mixin.dart:362:12)
E/flutter (28706): #9 SqfliteDatabaseExecutorMixin.rawInsert
(package:sqflite/src/database_mixin.dart:49:15)
E/flutter (28706): #10 SqfliteDatabaseExecutorMixin.insert
(package:sqflite/src/database_mixin.dart:59:12)
E/flutter (28706): #11 SQFliteDBHelper.SAVE_USER
(package:health_calorie_db/settings_in_app/sqflite_db_helper.dart:86:20)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #12 userServices.saveToSQFLiteDB
(package:health_calorie_db/dbServicesManager/userServices.dart:72:13)
E/flutter (28706): #13 userServices.logInCheck
(package:health_calorie_db/dbServicesManager/userServices.dart:99:10)
E/flutter (28706): <asynchronous suspension>
E/flutter (28706): #14 loginState.checkValidationForms
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:25:22)
E/flutter (28706): #15 loginState.build.<anonymous closure>.<anonymous closure>
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:112:60)
E/flutter (28706): #16 _createButton.build.<anonymous closure>
(package:health_calorie_db/ui_classes/log_in_up_pages/log_in_page.dart:165:9)
E/flutter (28706): #17 _InkResponseState._handleTap
(package:flutter/src/material/ink_well.dart:706:14)
E/flutter (28706): #18 _InkResponseState.build.<anonymous closure>
(package:flutter/src/material/ink_well.dart:789:36)
E/flutter (28706): #19 GestureRecognizer.invokeCallback
(package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (28706): #20 TapGestureRecognizer.handleTapUp
(package:flutter/src/gestures/tap.dart:486:11)
E/flutter (28706): #21 BaseTapGestureRecognizer._checkUp
(package:flutter/src/gestures/tap.dart:264:5)
E/flutter (28706): #22 BaseTapGestureRecognizer.acceptGesture
(package:flutter/src/gestures/tap.dart:236:7)
E/flutter (28706): #23 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (28706): #24 GestureBinding.handleEvent
(package:flutter/src/gestures/binding.dart:222:20)
E/flutter (28706): #25 GestureBinding.dispatchEvent
(package:flutter/src/gestures/binding.dart:198:22)
E/flutter (28706): #26 GestureBinding._handlePointerEvent
(package:flutter/src/gestures/binding.dart:156:7)
E/flutter (28706): #27 GestureBinding._flushPointerEventQueue
(package:flutter/src/gestures/binding.dart:102:7)
E/flutter (28706): #28 GestureBinding._handlePointerDataPacket
(package:flutter/src/gestures/binding.dart:86:7)
E/flutter (28706): #29 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (28706): #30 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (28706): #31 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (28706): #32 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (28706): #33 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
and here is the Code
FlatButton(
child: Text('Yes'),
onPressed: ()async {
setState(() {
dbHelper.deleteDB();
var duration = new Duration(seconds: 8);
return new Timer(duration, (){
exitApp();
});
});
},
Future<bool> deleteDB() async {
try{
deleteDatabase(path);
}catch( e){
print(e.toString());
}
print('deleting db');
}
exitApp()async {
Navigator.of(context).pushAndRemoveUntil(new MaterialPageRoute(builder: (context)=>login()),
(Route<dynamic> route) => false);
}
Future logInCheck(String name , String email, BuildContext buildContext) async
{
userModel user ;
final QuerySnapshot result = await userCollection.where('user_email', isEqualTo: email)
.where('user_name' , isEqualTo: name).limit(1).getDocuments(); // searching for a particular user
if(result.documents .length > 0){
final List<DocumentSnapshot> ds = result.documents;
for(int i=0; i< 1; i++ )
{
user = new userModel(ds[i].documentID, ds[i]['user_name'],ds[i]['user_email'],
ds[i]['user_gender'],
ds[i]['user_weight'],ds[i]['user_height'] ,ds[i]['cityPoint'] ,ds[i]['checkLogIn']);
print(user.user_email + ' : ' +user.user_id);
saveToSQFLiteDB(user);
print('Added');
}
nav.HOMEnavigate(buildContext,email);
} // if
else{
String msg = 'Couldnt find user with email \n fill with correct info' ;
nav.showSnackBar(buildContext , msg);
}
}
void saveToSQFLiteDB(userModel user) {
userInApp u = new userInApp(user.user_id, user.user_name, user.user_email, user.user_weight,
user.user_height, user.cityPoint.latitude, user.cityPoint.longitude,user.checkLogIN);
dbHelper.SAVE_USER(u);
}
Future<userInApp> SAVE_USER (userInApp user) async{
var dbClient = await datebase;
//user.user_id =
await dbClient.insert(userTable, user.toMap()).toString();
print('user has been saved');
return user;
}
I found the problem , I have to set db = null before deleting db , When I change deleteDB method to this , I t worked As I want .. Thanks
Future<void> deleteDB() async {
try{
print('deleting db');
db=null;
deleteDatabase(path);
}catch( e){
print(e.toString());
}
print('db is deleted');
}

glewInit Segfault with GLEW 2.0

I'm trying to write a simple program that just opens a window with GLEW 2.0 and GLFW 3, but am being met with a segfault...
Here is my source:
#include <stdio.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(int argc, char **argv) {
const int height = 100;
const int width = 100;
if (!glfwInit()) {
printf("Glfw failed to init\n");
return -1;
}
// 4x antialiasing
glfwWindowHint(GLFW_SAMPLES, 4);
// We want OpenGL 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// We don't want the old OpenGL
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window;
window = glfwCreateWindow(width, height, "Tutorial 01", NULL, NULL);
if (window == NULL) {
printf("GLFW Failed to open a window. "
"Intel GPUs don't support 3.3\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = 1;
if (glewInit() != GLEW_OK) {
printf("GLEW Failed to initialize.\n");
return -1;
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
do {
glfwSwapBuffers(window);
glfwPollEvents();
} while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
}
I compile this with
gcc test.c -g -lGLEW -lglfw -o test
And receive a segfault upon running the program. Using gdb, a backtrace on the segfault gives
0 0x0000000000000000 in ?? ()
1 0x00007ffff7ba02a7 in glxewInit () from /usr/lib64/libGLEW.so.2.0
2 0x00007ffff7ba87a3 in glewInit () from /usr/lib64/libGLEW.so.2.0
3 0x0000555555554bd4 in main (argc=1, argv=0x7fffffffdf18) at test.c:39
I am on Ubuntu 17.04, and I installed glew/glfw with Ubuntus pacakge manager with
sudo apt-get install libglew2.0 libglew-dev libglfw3 libglfw3-dev
I was following this tutorial here. If it makes any difference, I don't have a desktop manager or a compositor running. I'm using i3wm. However, the segfault still occurs when running alongside the compton compositor.
Lastly, just so I can provide some extra info, the ldd shows the linked libraries of test as
linux-vdso.so.1 => (0x00007ffc44ce9000)
libGLEW.so.2.0 => /usr/lib64/libGLEW.so.2.0 (0x00007f8e53dc9000)
libglfw.so.3 => /usr/lib/x86_64-linux-gnu/libglfw.so.3 (0x00007f8e53b86000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8e537bf000)
libGL.so.1 => /usr/lib/nvidia-375/libGL.so.1 (0x00007f8e5351b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f8e53313000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8e53008000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8e52e04000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f8e52acb000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8e528ad000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f8e526a2000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f8e5249f000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f8e52297000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f8e5208d000)
/lib64/ld-linux-x86-64.so.2 (0x000055e0ef28b000)
libGLX.so.0 => /usr/lib/nvidia-375/libGLX.so.0 (0x00007f8e51e5d000)
libGLdispatch.so.0 => /usr/lib/nvidia-375/libGLdispatch.so.0 (0x00007f8e51b8f000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f8e5196d000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f8e5175b000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f8e5154f000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f8e51349000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f8e51145000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f8e50f3f000)
Thanks for any help.
There is a bug report saying that core profile was broken in GLEW until 2.0.0.
Thus, you should update the GLEW. If that won't work, switch to compatibility profile by replacing GLFW_OPENGL_CORE_PROFILE flag with GLFW_OPENGL_COMPAT_PROFILE.

core dump during std::_List_node_base::unhook()

I have a program where std::list is used.
The program uses threads which act on the std::list as producers and consumers.
When a message is dealt with by the consumer, it is removed from the list using pop_front(). But, during pop_front, there is a core dump.
The gdb trace is as below. could you help getting me some insights into this issue?
(gdb) bt full
#0 0xf7531d7b in std::_List_node_base::unhook () from /usr/lib/libstdc++.so.6
No symbol table info available.
#1 0x0805c600 in std::list<myMsg, std::allocator<myMsg> >::_M_erase (this=0x806b08c,
__position={_M_node = 0x8075308})
at /opt/target/usr/include/c++/4.2.0/bits/stl_list.h:1169
__n = (class std::_List_node<myMsg> *) 0x0
#2 0x0805c6af in std::list<myMsg, std::allocator<myMsg> >::pop_front (this=0x806b08c)
at /opt/target/usr/include/c++/4.2.0/bits/stl_list.h:750
No locals.
#3 0x0805afb6 in Base::run () at ../../src/Base.cc:342
nSentBytes = 130
tmpnm = {_vptr.myMsg = 0x80652c0,
m_msg = 0x8075140 "{0130,MSG_TYPE=ND_FUNCTION,ORG_PNAME=P01vm01Ax,FUNCTION=LOG,PARAM_CNT=3,DATETIME=06/12/2010 02:59:26.187,LOGNAME=N,ENTRY=Debug 0 }", m_from = 0x8096ee0 "P01vm01Ax", m_to = 0x0,
static m_logged = false, static m_pLogMutex = {__data = {__lock = 0, __count = 0, __owner = 0,
__kind = 0, __nusers = 0, {__spins = 0, __list = {__next = 0x0}}},
__size = '\0' <repeats 23 times>, __align = 0}}
newMsg = {_vptr.myMsg = 0x80652c0, m_msg = 0x0, m_from = 0x0, m_to = 0x0,
static m_logged = false, static m_pLogMutex = {__data = {__lock = 0, __count = 0, __owner = 0,
__kind = 0, __nusers = 0, {__spins = 0, __list = {__next = 0x0}}},
__size = '\0' <repeats 23 times>, __align = 0}}
strBuffer = "{0440,MSG_TYPE=NG_FUNCTION,ORG_PNAME=mach01./opt/abc/VAvsk/abc/comp/DML/gendrs.pl.17560,DST_PNAME=P01vm01Ax,FUNCTION=DRS_REPLICATE,CAUSE_DML_ERROR=N,CORRUPT_DATA=N,CORRUPT_HEADER=N,DEBUG=Y,EXTENDED_RU"...
fds = {{fd = 5, events = 1, revents = 0}}
retval = 0
iWaitTime = 0
#4 0x0805b277 in startRun () at ../../src/Base.cc:454
No locals.
#5 0xf7effe7b in start_thread () from /lib/libpthread.so.0
No symbol table info available.
#6 0xf744d82e in clone () from /lib/libc.so.6
No symbol table info available.

Resources