Skip to content

Commit

Permalink
fix time-to-live deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Oct 3, 2023
1 parent cb72a81 commit 84c4069
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion magick/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type,
resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0));
resource_info.time_limit=MagickMin(resource_info.time_limit,
(MagickSizeType) MAGICK_SSIZE_MAX);
(void) GetMagickTTL();
(void) SetMagickTTL();
break;
}
case WidthResource:
Expand Down
3 changes: 3 additions & 0 deletions magick/timer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ extern MagickPrivate MagickOffsetType
extern MagickExport time_t
GetMagickTime(void);

extern MagickPrivate void
SetMagickTTL(void);

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Expand Down
23 changes: 14 additions & 9 deletions magick/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ static double

static void
StopTimer(TimerInfo *);
^L
/*
Static declarations.
*/
static time_t
magick_epoch = (time_t) 0;

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -374,18 +380,17 @@ MagickExport time_t GetMagickTime(void)
% MagickSizeType GetMagickTTL(void)
%
*/
MagickPrivate MagickOffsetType GetMagickTTL(void)

MagickPrivate void SetMagickTTL(void)
{
static time_t
epoch = (time_t) 0;
if (magick_epoch == 0)
magick_epoch=time((time_t *) NULL);
}

if (epoch == 0)
{
epoch=time((time_t *) NULL);
return(0);
}
MagickPrivate MagickOffsetType GetMagickTTL(void)
{
return((MagickOffsetType) GetMagickResourceLimit(TimeResource)-
(GetMagickTime()-epoch));
(GetMagickTime()-magick_epoch));
}

/*
Expand Down

0 comments on commit 84c4069

Please sign in to comment.