[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 01/01: Use `malloc' in `strsave'; use `free' for returned pointe
From: |
Werner LEMBERG |
Subject: |
[groff] 01/01: Use `malloc' in `strsave'; use `free' for returned pointers (#47164). |
Date: |
Mon, 15 Feb 2016 23:42:05 +0000 |
wl pushed a commit to branch master
in repository groff.
commit 5ee77445e5335ac3ffc19989a3f5c7e8e1bb386e
Author: Bálint Réczey <address@hidden>
Date: Tue Feb 16 00:40:53 2016 +0100
Use `malloc' in `strsave'; use `free' for returned pointers (#47164).
* src/libs/libgroff/font.cpp (text_file::~text_file): Use `free'.
* src/libs/libgroff/searchpath.cpp (search_path::open_file): Use
`free'.
* src/libs/libgroff/strsave.cpp: Include `stdlib.h'.
(strsave): Use `malloc'.
---
ChangeLog | 12 ++++++++++++
src/libs/libgroff/font.cpp | 2 +-
src/libs/libgroff/searchpath.cpp | 4 ++--
src/libs/libgroff/strsave.cpp | 3 ++-
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 14f0388..15bc013 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2016-02-16 Bálint Réczey <address@hidden>
+ Use `malloc' in `strsave'; use `free' for returned pointers.
+
+ * src/libs/libgroff/font.cpp (text_file::~text_file): Use `free'.
+
+ * src/libs/libgroff/searchpath.cpp (search_path::open_file): Use
+ `free'.
+
+ * src/libs/libgroff/strsave.cpp: Include `stdlib.h'.
+ (strsave): Use `malloc'.
+
+2016-02-16 Bálint Réczey <address@hidden>
+
Simplify memory allocation (#47162).
Many invalid memory accesses were caught by UBSAN (e.g., invalid
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index 047a0b8..8c6ef0a 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -90,7 +90,7 @@ text_file::text_file(FILE *p, char *s)
text_file::~text_file()
{
a_delete buf;
- a_delete path;
+ free(path);
if (fp)
fclose(fp);
}
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index f9efe11..5bd1bbc 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -130,10 +130,10 @@ FILE *search_path::open_file(const char *name, char
**pathp)
if (pathp)
*pathp = path;
else
- a_delete path;
+ free(path);
return fp;
}
- a_delete path;
+ free(path);
if (*end == '\0')
break;
p = end + 1;
diff --git a/src/libs/libgroff/strsave.cpp b/src/libs/libgroff/strsave.cpp
index b8b69cc..f95cfd5 100644
--- a/src/libs/libgroff/strsave.cpp
+++ b/src/libs/libgroff/strsave.cpp
@@ -18,12 +18,13 @@ You should have received a copy of the GNU General Public
License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <string.h>
+#include <stdlib.h>
char *strsave(const char *s)
{
if (s == 0)
return 0;
- char *p = new char[strlen(s) + 1];
+ char *p = (char*)malloc(strlen(s) + 1);
strcpy(p, s);
return p;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 01/01: Use `malloc' in `strsave'; use `free' for returned pointers (#47164).,
Werner LEMBERG <=