mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 06:41:13 +02:00
(scm_getcwd, scm_readlink): Avoid memory leak on errors.
This commit is contained in:
parent
7fd8fe2cd5
commit
50af014bb7
1 changed files with 14 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
|
/* Copyright (C) 1996,1997,1998,1999,2000,2001,2004 Free Software Foundation, Inc.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -868,7 +868,13 @@ SCM_DEFINE (scm_getcwd, "getcwd", 0, 0, 0,
|
||||||
wd = scm_must_malloc (size, FUNC_NAME);
|
wd = scm_must_malloc (size, FUNC_NAME);
|
||||||
}
|
}
|
||||||
if (rv == 0)
|
if (rv == 0)
|
||||||
SCM_SYSERROR;
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
free (wd);
|
||||||
|
errno = save_errno;
|
||||||
|
SCM_SYSERROR;
|
||||||
|
}
|
||||||
|
SCM_SYSERROR;
|
||||||
result = scm_mem2string (wd, strlen (wd));
|
result = scm_mem2string (wd, strlen (wd));
|
||||||
scm_must_free (wd);
|
scm_must_free (wd);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1296,7 +1302,12 @@ SCM_DEFINE (scm_readlink, "readlink", 1, 0, 0,
|
||||||
buf = scm_must_malloc (size, FUNC_NAME);
|
buf = scm_must_malloc (size, FUNC_NAME);
|
||||||
}
|
}
|
||||||
if (rv == -1)
|
if (rv == -1)
|
||||||
SCM_SYSERROR;
|
{
|
||||||
|
int save_errno = errno;
|
||||||
|
free (buf);
|
||||||
|
errno = save_errno;
|
||||||
|
SCM_SYSERROR;
|
||||||
|
}
|
||||||
result = scm_mem2string (buf, rv);
|
result = scm_mem2string (buf, rv);
|
||||||
scm_must_free (buf);
|
scm_must_free (buf);
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue