Permalink
Browse files

Fix a crash when deleting an image from keywords mode

  • Loading branch information...
1 parent 5e0dec0 commit 0a8179b49c4629740b924381e0890879f834ba50 @akkana committed Aug 12, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −0 dialogs.h
  2. +10 −1 keydialog.c
  3. +3 −0 pho.c
View
@@ -21,6 +21,7 @@ extern void ShowKeywordsDialog();
extern void HideKeywordsDialog();
extern void UpdateKeywordsDialog();
extern void RememberKeywords();
+extern void NoCurrentKeywords(); /* use when deleting current image */
/* A function dialogs must call to stay on top of the image window */
extern void KeepOnTop(GtkWidget* dialog);
View
@@ -58,7 +58,16 @@ void RememberKeywords()
/* and save a caption, if any */
if (sLastImage->caption)
free(sLastImage->caption);
- sLastImage->caption = strdup((char*)gtk_entry_get_text((GtkEntry*)KeywordsCaption));
+ sLastImage->caption = strdup((char*)gtk_entry_get_text(
+ (GtkEntry*)KeywordsCaption));
+}
+
+/* When deleting an image, we need to clear any notion of sLastImage
+ * or else we'll crash trying to access it.
+ */
+void NoCurrentKeywords()
+{
+ sLastImage = 0;
}
void SetKeywordsDialogToggle(int which, int newval)
View
@@ -590,6 +590,9 @@ PhoImage* NewPhoImage(char* fnam)
void ReallyDelete(PhoImage* delImg)
{
+ /* Make sure the keywords dialog doesn't save a pointer to this image */
+ NoCurrentKeywords();
+
if (unlink(delImg->filename) < 0)
{
printf("OOPS! Can't delete %s\n", delImg->filename);

0 comments on commit 0a8179b

Please sign in to comment.