aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-07 22:17:08 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-07 22:17:08 +0100
commit0bcf6185b031ccd74e6c39bdfb5d21a71e8992b1 (patch)
tree804d8c1b4140466465e8ce355d106a1fa46327ea /src
parent38d030f301cc781a56cab5724175a127f2eb1230 (diff)
Free image data on final unref
Diffstat (limited to 'src')
-rw-r--r--src/objects.c22
-rw-r--r--src/objects.h4
2 files changed, 24 insertions, 2 deletions
diff --git a/src/objects.c b/src/objects.c
index 01e347e..263c7b2 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -75,6 +75,7 @@ static struct image *add_image_to_store(struct image_store *is, char *filename)
i_new->refcount = 1;
i_new->width = w;
i_new->height = h;
+ i_new->parent = is;
is->images[idx] = i_new;
@@ -116,7 +117,26 @@ void unref_image(struct image *i)
i->refcount--;
if ( i->refcount == 0 ) {
- /* FIXME: Delete image */
+
+ struct image_store *is;
+ int j;
+
+ g_object_unref(G_OBJECT(i->pb));
+ free(i->filename);
+ is = i->parent;
+ free(i);
+
+ for ( j=0; j<is->n_images; j++ ) {
+ if ( is->images[j] == i ) {
+ int k;
+ for ( k=j+1; k<is->n_images; k++ ) {
+ is->images[k-1] = is->images[k];
+ }
+ break;
+ }
+ }
+ is->n_images--;
+
}
}
diff --git a/src/objects.h b/src/objects.h
index fd567e1..6fd3a42 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -71,7 +71,9 @@ struct image
int width;
int height;
- int refcount;
+ int refcount;
+
+ struct image_store *parent;
};