diff options
| author | Paul Eggert | 2013-08-19 00:01:37 -0700 |
|---|---|---|
| committer | Paul Eggert | 2013-08-19 00:01:37 -0700 |
| commit | d0139df5b60d235363e78438316e255ac378c884 (patch) | |
| tree | 1ff811c2211a04fa56ddcccdd8986c2f2bb22756 /src | |
| parent | 2249012558e589b9382e068326116dbd909bbb81 (diff) | |
| download | emacs-d0139df5b60d235363e78438316e255ac378c884.tar.gz emacs-d0139df5b60d235363e78438316e255ac378c884.zip | |
* image.c: Fix animation cache signature memory leak.
Fix some other minor performance problems while we're at it.
(imagemagick_create_cache): Clear just the members that
need clearing. Don't set update_time, as caller does that now.
(imagemagick_prune_animation_cache, imagemagick_get_animation_cache):
Simplify by using pointer-to-pointer instead of a prev pointer.
(imagemagick_prune_animation_cache): Use make_emacs_time rather
than EMACS_TIME_FROM_DOUBLE, and DestroyString rather than free.
(imagemagick_get_animation_cache): Don't xstrdup the image signature;
it's already a copy. Free the signature probe unless it's cached.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/image.c | 62 |
2 files changed, 39 insertions, 34 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 0203ce636ef..c5a6f4d19c3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,16 @@ | |||
| 1 | 2013-08-19 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2013-08-19 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * image.c: Fix animation cache signature memory leak. | ||
| 4 | Fix some other minor performance problems while we're at it. | ||
| 5 | (imagemagick_create_cache): Clear just the members that | ||
| 6 | need clearing. Don't set update_time, as caller does that now. | ||
| 7 | (imagemagick_prune_animation_cache, imagemagick_get_animation_cache): | ||
| 8 | Simplify by using pointer-to-pointer instead of a prev pointer. | ||
| 9 | (imagemagick_prune_animation_cache): Use make_emacs_time rather | ||
| 10 | than EMACS_TIME_FROM_DOUBLE, and DestroyString rather than free. | ||
| 11 | (imagemagick_get_animation_cache): Don't xstrdup the image signature; | ||
| 12 | it's already a copy. Free the signature probe unless it's cached. | ||
| 13 | |||
| 3 | * process.c (handle_child_signal): Fix crash; deleted pid (Bug#15106). | 14 | * process.c (handle_child_signal): Fix crash; deleted pid (Bug#15106). |
| 4 | This was introduced by my 2013-08-12 fix for Bug#15035. | 15 | This was introduced by my 2013-08-12 fix for Bug#15035. |
| 5 | 16 | ||
diff --git a/src/image.c b/src/image.c index a8210e2414a..68d78fc9eef 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -7890,9 +7890,11 @@ static struct animation_cache *animation_cache = NULL; | |||
| 7890 | static struct animation_cache * | 7890 | static struct animation_cache * |
| 7891 | imagemagick_create_cache (char *signature) | 7891 | imagemagick_create_cache (char *signature) |
| 7892 | { | 7892 | { |
| 7893 | struct animation_cache *cache = xzalloc (sizeof *cache); | 7893 | struct animation_cache *cache = xmalloc (sizeof *cache); |
| 7894 | cache->signature = signature; | 7894 | cache->signature = signature; |
| 7895 | cache->update_time = current_emacs_time (); | 7895 | cache->wand = 0; |
| 7896 | cache->index = 0; | ||
| 7897 | cache->next = 0; | ||
| 7896 | return cache; | 7898 | return cache; |
| 7897 | } | 7899 | } |
| 7898 | 7900 | ||
| @@ -7900,30 +7902,22 @@ imagemagick_create_cache (char *signature) | |||
| 7900 | static void | 7902 | static void |
| 7901 | imagemagick_prune_animation_cache (void) | 7903 | imagemagick_prune_animation_cache (void) |
| 7902 | { | 7904 | { |
| 7903 | struct animation_cache *cache = animation_cache; | 7905 | struct animation_cache **pcache = &animation_cache; |
| 7904 | struct animation_cache *prev = NULL; | ||
| 7905 | EMACS_TIME old = sub_emacs_time (current_emacs_time (), | 7906 | EMACS_TIME old = sub_emacs_time (current_emacs_time (), |
| 7906 | EMACS_TIME_FROM_DOUBLE (60)); | 7907 | make_emacs_time (60, 0)); |
| 7907 | 7908 | ||
| 7908 | while (cache) | 7909 | while (*pcache) |
| 7909 | { | 7910 | { |
| 7910 | if (EMACS_TIME_LT (cache->update_time, old)) | 7911 | struct animation_cache *cache = *pcache; |
| 7912 | if (EMACS_TIME_LE (old, cache->update_time)) | ||
| 7913 | pcache = &cache->next; | ||
| 7914 | else | ||
| 7911 | { | 7915 | { |
| 7912 | struct animation_cache *this_cache = cache; | 7916 | DestroyString (cache->signature); |
| 7913 | free (cache->signature); | ||
| 7914 | if (cache->wand) | 7917 | if (cache->wand) |
| 7915 | DestroyMagickWand (cache->wand); | 7918 | DestroyMagickWand (cache->wand); |
| 7916 | if (prev) | 7919 | *pcache = cache->next; |
| 7917 | prev->next = cache->next; | 7920 | xfree (cache); |
| 7918 | else | ||
| 7919 | animation_cache = cache->next; | ||
| 7920 | cache = cache->next; | ||
| 7921 | free (this_cache); | ||
| 7922 | } | ||
| 7923 | else | ||
| 7924 | { | ||
| 7925 | prev = cache; | ||
| 7926 | cache = cache->next; | ||
| 7927 | } | 7921 | } |
| 7928 | } | 7922 | } |
| 7929 | } | 7923 | } |
| @@ -7931,26 +7925,26 @@ imagemagick_prune_animation_cache (void) | |||
| 7931 | static struct animation_cache * | 7925 | static struct animation_cache * |
| 7932 | imagemagick_get_animation_cache (MagickWand *wand) | 7926 | imagemagick_get_animation_cache (MagickWand *wand) |
| 7933 | { | 7927 | { |
| 7934 | char *signature = xstrdup (MagickGetImageSignature (wand)); | 7928 | char *signature = MagickGetImageSignature (wand); |
| 7935 | struct animation_cache *cache; | 7929 | struct animation_cache *cache; |
| 7930 | struct animation_cache **pcache = &animation_cache; | ||
| 7936 | 7931 | ||
| 7937 | imagemagick_prune_animation_cache (); | 7932 | imagemagick_prune_animation_cache (); |
| 7938 | cache = animation_cache; | 7933 | cache = animation_cache; |
| 7939 | 7934 | ||
| 7940 | if (! cache) | 7935 | for (pcache = &animation_cache; *pcache; pcache = &cache->next) |
| 7941 | { | ||
| 7942 | animation_cache = imagemagick_create_cache (signature); | ||
| 7943 | return animation_cache; | ||
| 7944 | } | ||
| 7945 | |||
| 7946 | while (strcmp(signature, cache->signature) && | ||
| 7947 | cache->next) | ||
| 7948 | cache = cache->next; | ||
| 7949 | |||
| 7950 | if (strcmp(signature, cache->signature)) | ||
| 7951 | { | 7936 | { |
| 7952 | cache->next = imagemagick_create_cache (signature); | 7937 | cache = *pcache; |
| 7953 | return cache->next; | 7938 | if (! cache) |
| 7939 | { | ||
| 7940 | *pcache = cache = imagemagick_create_cache (signature); | ||
| 7941 | break; | ||
| 7942 | } | ||
| 7943 | if (strcmp (signature, cache->signature) == 0) | ||
| 7944 | { | ||
| 7945 | DestroyString (signature); | ||
| 7946 | break; | ||
| 7947 | } | ||
| 7954 | } | 7948 | } |
| 7955 | 7949 | ||
| 7956 | cache->update_time = current_emacs_time (); | 7950 | cache->update_time = current_emacs_time (); |