mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-11 14:21:10 +02:00
* socket.c (scm_bind): free soka after use.
* stime.c (tzvar): new variable. (setzone, restorezone, scm_localtime, scm_mktime, scm_strftime): avoid memory leaks when allocating.
This commit is contained in:
parent
7a35faf841
commit
ef9ff3fd0a
3 changed files with 74 additions and 59 deletions
|
@ -1,3 +1,13 @@
|
||||||
|
Sun Jan 4 02:23:36 1998 Gary Houston <ghouston@actrix.gen.nz>
|
||||||
|
|
||||||
|
* socket.c (scm_bind): free soka after use.
|
||||||
|
|
||||||
|
Sat Jan 3 20:55:07 1998 Gary Houston <ghouston@actrix.gen.nz>
|
||||||
|
|
||||||
|
* stime.c (tzvar): new variable.
|
||||||
|
(setzone, restorezone, scm_localtime, scm_mktime, scm_strftime):
|
||||||
|
avoid memory leaks when allocating.
|
||||||
|
|
||||||
1998-01-03 Jim Blandy <jimb@totoro.red-bean.com>
|
1998-01-03 Jim Blandy <jimb@totoro.red-bean.com>
|
||||||
|
|
||||||
* iselect.h: Some systems require <sys/types.h> to get the FD_SET
|
* iselect.h: Some systems require <sys/types.h> to get the FD_SET
|
||||||
|
|
|
@ -425,6 +425,7 @@ scm_bind (sock, fam, address, args)
|
||||||
rv = bind (fd, soka, size);
|
rv = bind (fd, soka, size);
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
scm_syserror (s_bind);
|
scm_syserror (s_bind);
|
||||||
|
scm_must_free ((char *) soka);
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
122
libguile/stime.c
122
libguile/stime.c
|
@ -261,45 +261,41 @@ filltime (struct tm *bd_time, int zoff, char *zname)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char tzvar[3] = "TZ";
|
||||||
|
extern char ** environ;
|
||||||
|
|
||||||
|
static char **
|
||||||
setzone (SCM zone, int pos, char *subr)
|
setzone (SCM zone, int pos, char *subr)
|
||||||
{
|
{
|
||||||
char *oldtz = 0;
|
char **oldenv = 0;
|
||||||
|
|
||||||
if (!SCM_UNBNDP (zone))
|
if (!SCM_UNBNDP (zone))
|
||||||
{
|
{
|
||||||
|
static char *tmpenv[2];
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
/* if zone was supplied, set the environment variable TZ temporarily. */
|
/* if zone was supplied, set the environment temporarily. */
|
||||||
SCM_ASSERT (SCM_NIMP (zone) && SCM_ROSTRINGP (zone), zone, pos, subr);
|
SCM_ASSERT (SCM_NIMP (zone) && SCM_ROSTRINGP (zone), zone, pos, subr);
|
||||||
SCM_COERCE_SUBSTR (zone);
|
SCM_COERCE_SUBSTR (zone);
|
||||||
buf = malloc (SCM_LENGTH (zone) + 4);
|
buf = scm_must_malloc (SCM_LENGTH (zone) + sizeof (tzvar) + 1,
|
||||||
if (buf == 0)
|
subr);
|
||||||
scm_memory_error (subr);
|
sprintf (buf, "%s=%s", tzvar, SCM_ROCHARS (zone));
|
||||||
oldtz = getenv ("TZ");
|
oldenv = environ;
|
||||||
if (oldtz != NULL)
|
tmpenv[0] = buf;
|
||||||
oldtz = oldtz - 3;
|
tmpenv[1] = 0;
|
||||||
sprintf (buf, "TZ=%s", SCM_ROCHARS (zone));
|
environ = tmpenv;
|
||||||
if (putenv (buf) < 0)
|
|
||||||
scm_syserror (subr);
|
|
||||||
tzset();
|
tzset();
|
||||||
}
|
}
|
||||||
return oldtz;
|
return oldenv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
restorezone (SCM zone, char *oldzone)
|
restorezone (SCM zone, char **oldenv, char *subr)
|
||||||
{
|
{
|
||||||
if (!SCM_UNBNDP (zone))
|
if (!SCM_UNBNDP (zone))
|
||||||
{
|
{
|
||||||
int rv;
|
scm_must_free (environ[0]);
|
||||||
|
environ = oldenv;
|
||||||
if (oldzone)
|
|
||||||
rv = putenv (oldzone);
|
|
||||||
else
|
|
||||||
rv = putenv ("TZ");
|
|
||||||
if (rv < 0)
|
|
||||||
scm_syserror ("restorezone");
|
|
||||||
tzset();
|
tzset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,38 +310,39 @@ scm_localtime (SCM time, SCM zone)
|
||||||
SCM result;
|
SCM result;
|
||||||
int zoff;
|
int zoff;
|
||||||
char *zname = 0;
|
char *zname = 0;
|
||||||
char *oldtz;
|
char **oldenv;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
itime = scm_num2long (time, (char *) SCM_ARG1, s_localtime);
|
itime = scm_num2long (time, (char *) SCM_ARG1, s_localtime);
|
||||||
SCM_DEFER_INTS;
|
SCM_DEFER_INTS;
|
||||||
oldtz = setzone (zone, SCM_ARG2, s_localtime);
|
oldenv = setzone (zone, SCM_ARG2, s_localtime);
|
||||||
ltptr = localtime (&itime);
|
ltptr = localtime (&itime);
|
||||||
err = errno;
|
err = errno;
|
||||||
/* copied in case localtime and gmtime share a buffer. */
|
|
||||||
if (ltptr)
|
|
||||||
lt = *ltptr;
|
|
||||||
utc = gmtime (&itime);
|
|
||||||
if (utc == NULL)
|
|
||||||
err = errno;
|
|
||||||
if (ltptr)
|
if (ltptr)
|
||||||
{
|
{
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
/* copy zone name before calling gmtime or tzset. */
|
||||||
#ifdef HAVE_TM_ZONE
|
#ifdef HAVE_TM_ZONE
|
||||||
zname = lt.tm_zone;
|
ptr = ltptr->tm_zone;
|
||||||
#else
|
#else
|
||||||
# ifdef HAVE_TZNAME
|
# ifdef HAVE_TZNAME
|
||||||
/* must be copied before calling tzset again. */
|
ptr = tzname[ (ltptr->tm_isdst == 1) ? 1 : 0 ];
|
||||||
char *ptr = tzname[ (lt.tm_isdst == 1) ? 1 : 0 ];
|
|
||||||
|
|
||||||
zname = scm_must_malloc (strlen (ptr) + 1, s_localtime);
|
|
||||||
strcpy (zname, ptr);
|
|
||||||
# else
|
# else
|
||||||
scm_misc_error (s_localtime, "Not fully implemented on this platform",
|
scm_misc_error (s_localtime, "Not fully implemented on this platform",
|
||||||
SCM_EOL);
|
SCM_EOL);
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
zname = scm_must_malloc (strlen (ptr) + 1, s_localtime);
|
||||||
|
strcpy (zname, ptr);
|
||||||
}
|
}
|
||||||
restorezone (zone, oldtz);
|
/* the struct is copied in case localtime and gmtime share a buffer. */
|
||||||
|
if (ltptr)
|
||||||
|
lt = *ltptr;
|
||||||
|
utc = gmtime (&itime);
|
||||||
|
if (utc == NULL)
|
||||||
|
err = errno;
|
||||||
|
restorezone (zone, oldenv, s_localtime);
|
||||||
/* delayed until zone has been restored. */
|
/* delayed until zone has been restored. */
|
||||||
errno = err;
|
errno = err;
|
||||||
if (utc == NULL || ltptr == NULL)
|
if (utc == NULL || ltptr == NULL)
|
||||||
|
@ -365,6 +362,7 @@ scm_localtime (SCM time, SCM zone)
|
||||||
|
|
||||||
result = filltime (<, zoff, zname);
|
result = filltime (<, zoff, zname);
|
||||||
SCM_ALLOW_INTS;
|
SCM_ALLOW_INTS;
|
||||||
|
scm_must_free (zname);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +420,7 @@ scm_mktime (SCM sbd_time, SCM zone)
|
||||||
SCM result;
|
SCM result;
|
||||||
int zoff;
|
int zoff;
|
||||||
char *zname = 0;
|
char *zname = 0;
|
||||||
char *oldtz = 0;
|
char **oldenv;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
SCM_ASSERT (SCM_NIMP (sbd_time) && SCM_VECTORP (sbd_time), sbd_time,
|
SCM_ASSERT (SCM_NIMP (sbd_time) && SCM_VECTORP (sbd_time), sbd_time,
|
||||||
|
@ -430,33 +428,35 @@ scm_mktime (SCM sbd_time, SCM zone)
|
||||||
bdtime2c (sbd_time, <, SCM_ARG1, s_mktime);
|
bdtime2c (sbd_time, <, SCM_ARG1, s_mktime);
|
||||||
|
|
||||||
SCM_DEFER_INTS;
|
SCM_DEFER_INTS;
|
||||||
oldtz = setzone (zone, SCM_ARG2, s_mktime);
|
oldenv = setzone (zone, SCM_ARG2, s_mktime);
|
||||||
itime = mktime (<);
|
itime = mktime (<);
|
||||||
err = errno;
|
err = errno;
|
||||||
|
|
||||||
/* timezone offset in seconds west of UTC. */
|
if (itime != -1)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
/* copy zone name before calling gmtime or tzset. */
|
||||||
|
#ifdef HAVE_TM_ZONE
|
||||||
|
ptr = lt.tm_zone;
|
||||||
|
#else
|
||||||
|
# ifdef HAVE_TZNAME
|
||||||
|
ptr = tzname[ (lt.tm_isdst == 1) ? 1 : 0 ];
|
||||||
|
# else
|
||||||
|
scm_misc_error (s_mktime, "Not fully implemented on this platform",
|
||||||
|
SCM_EOL);
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
zname = scm_must_malloc (strlen (ptr) + 1, s_mktime);
|
||||||
|
strcpy (zname, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get timezone offset in seconds west of UTC. */
|
||||||
utc = gmtime (&itime);
|
utc = gmtime (&itime);
|
||||||
if (utc == NULL)
|
if (utc == NULL)
|
||||||
err = errno;
|
err = errno;
|
||||||
|
|
||||||
if (itime != -1)
|
restorezone (zone, oldenv, s_mktime);
|
||||||
{
|
|
||||||
#ifdef HAVE_TM_ZONE
|
|
||||||
zname = lt.tm_zone;
|
|
||||||
#else
|
|
||||||
# ifdef HAVE_TZNAME
|
|
||||||
/* must be copied before calling tzset again. */
|
|
||||||
char *ptr = tzname[ (lt.tm_isdst == 1) ? 1 : 0 ];
|
|
||||||
|
|
||||||
zname = scm_must_malloc (strlen (ptr) + 1, s_mktime);
|
|
||||||
strcpy (zname, ptr);
|
|
||||||
# else
|
|
||||||
scm_misc_error (s_localtime, "Not fully implemented on this platform",
|
|
||||||
SCM_EOL);
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
restorezone (zone, oldtz);
|
|
||||||
/* delayed until zone has been restored. */
|
/* delayed until zone has been restored. */
|
||||||
errno = err;
|
errno = err;
|
||||||
if (utc == NULL || itime == -1)
|
if (utc == NULL || itime == -1)
|
||||||
|
@ -476,6 +476,7 @@ scm_mktime (SCM sbd_time, SCM zone)
|
||||||
result = scm_cons (scm_long2num ((long) itime),
|
result = scm_cons (scm_long2num ((long) itime),
|
||||||
filltime (<, zoff, zname));
|
filltime (<, zoff, zname));
|
||||||
SCM_ALLOW_INTS;
|
SCM_ALLOW_INTS;
|
||||||
|
scm_must_free (zname);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,6 +501,7 @@ scm_strftime (format, stime)
|
||||||
int size = 50;
|
int size = 50;
|
||||||
char *fmt;
|
char *fmt;
|
||||||
int len;
|
int len;
|
||||||
|
SCM result;
|
||||||
|
|
||||||
SCM_ASSERT (SCM_NIMP (format) && SCM_ROSTRINGP (format), format, SCM_ARG1,
|
SCM_ASSERT (SCM_NIMP (format) && SCM_ROSTRINGP (format), format, SCM_ARG1,
|
||||||
s_strftime);
|
s_strftime);
|
||||||
|
@ -516,7 +518,9 @@ scm_strftime (format, stime)
|
||||||
size *= 2;
|
size *= 2;
|
||||||
tbuf = scm_must_malloc (size, s_strftime);
|
tbuf = scm_must_malloc (size, s_strftime);
|
||||||
}
|
}
|
||||||
return scm_makfromstr (tbuf, len, 0);
|
result = scm_makfromstr (tbuf, len, 0);
|
||||||
|
scm_must_free (tbuf);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM_PROC (s_strptime, "strptime", 2, 0, 0, scm_strptime);
|
SCM_PROC (s_strptime, "strptime", 2, 0, 0, scm_strptime);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue