Package: gqcam
Version: 0.9.1-5
Severity: important

If gqcam is closed with Alt+F4 and not with File/Quit menu item then
the ~/.gqcamrc will be corrupted.

How to reproduce: first apply the attached debug patch then compile and
run gqcam. Press Alt+F4 to close gqcam.

$ rm ~/.gqcamrc
$ gqcam-0.9.1/gqcam -v /dev/video0
gqcam.c:459: &camera=0x8058640
frontend.c:605: camera=0x8058640
frontend.c:653: camera=0x8058640
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
Error reading image...
camera->inputtype=0x0
gqcam.c:400: camera=0x8458798
gqcam.c:401: camera->inputtype=0x845A908
preferences.c:205: camera=0x8458798
Error reading image...
$ cat ~/.gqcamrc
autobrightness 0
swaprgb 4
inputtype 138782984

As you can see the "camera" pointer at gqcam.c:delete_event() is already wrong
(0x8458798 instead of 0x8058640) which means that the saved .gqcamrc file will
be corrupted.
diff -upr gqcam-0.9.1.orig/frontend.c gqcam-0.9.1/frontend.c
--- gqcam-0.9.1.orig/frontend.c	2008-10-19 12:35:45.000000000 +0200
+++ gqcam-0.9.1/frontend.c	2008-10-19 12:38:52.000000000 +0200
@@ -443,6 +443,8 @@ void dock_controls(GtkWidget *widget, st
     camera->controlwindow = gtk_window_new(GTK_WINDOW_DIALOG);
     gtk_container_add (GTK_CONTAINER(camera->controlwindow), camera->controltop);
     gtk_window_set_title(GTK_WINDOW (camera->controlwindow), "Gqcam - Control Panel");
+
+    printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
     gtk_signal_connect (GTK_OBJECT (camera->controlwindow), "delete_event",
 			GTK_SIGNAL_FUNC (close_controls), camera);
     gtk_widget_show(camera->controlwindow);
@@ -599,6 +601,8 @@ int create_frontend(struct Camera *camer
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), title);
   gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
+
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   gtk_signal_connect (GTK_OBJECT (window), "delete_event",
 		      GTK_SIGNAL_FUNC (delete_event), camera);
 
@@ -645,6 +649,8 @@ int create_frontend(struct Camera *camer
 
   quititem = gtk_menu_item_new_with_label("Quit");
   gtk_menu_append(GTK_MENU(filemenu), quititem);
+
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   gtk_signal_connect(GTK_OBJECT (quititem), "activate",
 		     GTK_SIGNAL_FUNC (delete_event),
 		     camera);
diff -upr gqcam-0.9.1.orig/gqcam.c gqcam-0.9.1/gqcam.c
--- gqcam-0.9.1.orig/gqcam.c	2008-10-19 12:35:45.000000000 +0200
+++ gqcam-0.9.1/gqcam.c	2008-10-19 12:42:15.000000000 +0200
@@ -287,6 +287,8 @@ void grab_image(struct Camera *camera)
   while ( !plsquit ) {
     // order matters! the sem_waits MUST be before the mutex lock
     
+    printf("camera->inputtype=0x%X\n", camera->inputtype);
+
     if( !sem_wait( &s_grab1 ) && ( camera->speed_fastest || !sem_wait( &s_grab2 ) ) && !pthread_mutex_lock( &camera->freeze_mutex ) && !pthread_mutex_lock( &camera->iscam_mutex )){
 
       pthread_mutex_lock( &camera->pref_mutex );
@@ -395,6 +397,9 @@ void delete_event(GtkWidget *widget, str
   char * savefile;
   char * path = "/.gqcamrc";
 
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
+  printf("%s:%u: camera->inputtype=0x%X\n", __FILE__, __LINE__, camera->inputtype);
+
   if((home = getenv("HOME")) != NULL && (savefile = malloc(strlen(home)
 				  + strlen(path) + 1)) != NULL)
   {
@@ -451,6 +456,7 @@ int main(int argc, char *argv[])
   int done = 0;
   FILE *preffile;
 
+  printf("%s:%u: &camera=%p\n", __FILE__, __LINE__, &camera);
   init_cam(&camera);
 /*
   g_thread_init(NULL);
diff -upr gqcam-0.9.1.orig/preferences.c gqcam-0.9.1/preferences.c
--- gqcam-0.9.1.orig/preferences.c	2005-04-04 03:25:09.000000000 +0200
+++ gqcam-0.9.1/preferences.c	2008-10-19 12:22:33.000000000 +0200
@@ -65,6 +65,7 @@ void pref_dialog(GtkWidget *widget, stru
   GtkWidget *label;
   */
 
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   camera->pref_dialog.prefdialog = gtk_dialog_new();
 
   camera->pref_dialog.prefnotebook = gtk_notebook_new();
@@ -180,6 +181,7 @@ void read_pref_file(FILE *input, struct 
   char buff[1024], command[1024];  
   int val=0;
   
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   while(fgets(buff, sizeof(buff), input) != NULL){
     if((buff[0] != '#') && (buff[0] != '\n'))
       {
@@ -200,6 +202,7 @@ void read_pref_file(FILE *input, struct 
 
 void save_pref_file(FILE *output, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   fprintf(output, "autobrightness %d\n", camera->autobright);
   fprintf(output, "swaprgb %d\n", camera->swapcolors);
   fprintf(output, "inputtype %d\n", camera->inputtype);
@@ -207,6 +210,7 @@ void save_pref_file(FILE *output, struct
 
 void ok_prefs(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   apply_prefs(widget, camera);
   closedialog(widget, camera->pref_dialog.prefdialog);
 }
@@ -214,6 +218,7 @@ void ok_prefs(GtkWidget *widget, struct 
 
 void apply_prefs(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(camera->pref_dialog.rgbswap)))
     camera->swapcolors = 1;
   else
diff -upr gqcam-0.9.1.orig/timer.c gqcam-0.9.1/timer.c
--- gqcam-0.9.1.orig/timer.c	2008-10-19 12:35:45.000000000 +0200
+++ gqcam-0.9.1/timer.c	2008-10-19 12:20:13.000000000 +0200
@@ -39,21 +39,25 @@
 
 void set_timer_seconds(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   camera->timer_struct.unit = SECONDS;
 }
 
 void set_timer_minutes(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   camera->timer_struct.unit = MINUTES;
 }
 
 void timer_snap_now(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   next_frame(camera);
 }
 
 void timer_stop_timer(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   camera->on_timer = 0;
   gtk_timeout_remove(camera->timeoutid);
   if(!camera->timeout)
@@ -75,6 +79,7 @@ void timer_ok(GtkWidget *widget, struct 
   int timeout;
   char snaplabeltext[30];
   
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   if(strlen(gtk_entry_get_text(GTK_ENTRY(camera->timer_struct.commandentry))) > 255){
     printf("Command too long...\n");
     return;
@@ -140,6 +145,7 @@ void timer_ok(GtkWidget *widget, struct 
 
 void timer_cancel(GtkWidget *widget, struct Camera *camera)
 {
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   //camera->on_timer = 0;
   gtk_widget_destroy(camera->timer_struct.timerdialog);
 }
@@ -163,6 +169,7 @@ void set_timer(GtkWidget *widget, struct
   GtkWidget *okbutton;
   GtkWidget *cancelbutton;
 */
+  printf("%s:%u: camera=%p\n", __FILE__, __LINE__, camera);
   //  camera->on_timer = 1;
   
   camera->timer_struct.timerdialog = gtk_dialog_new();

Reply via email to