diff options
author | imp <imp@FreeBSD.org> | 1998-09-16 04:17:47 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 1998-09-16 04:17:47 +0000 |
commit | bfe73fd683053201c326f9ff2c8e5e0f69cc7fe7 (patch) | |
tree | b17d45198953bfbbad4bfd632dfdf1a37b7159d2 /lib/libc/gen | |
parent | 68a8c771724d4fc671cac3ce95f78d4fb1874cfe (diff) | |
download | FreeBSD-src-bfe73fd683053201c326f9ff2c8e5e0f69cc7fe7.zip FreeBSD-src-bfe73fd683053201c326f9ff2c8e5e0f69cc7fe7.tar.gz |
Replace memory leaking instances of realloc with non-leaking reallocf.
In some cases replace if (a == null) a = malloc(x); else a =
realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is
guaranteed to be the same thing.
I've been running these on my system here w/o ill effects for some
time. However, the CTM-express is at part 6 of 34 for the CAM
changes, so I've not been able to do a build world with the CAM in the
tree with these changes. Shouldn't impact anything, but...
Diffstat (limited to 'lib/libc/gen')
-rw-r--r-- | lib/libc/gen/fts-compat.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/fts.c | 4 | ||||
-rw-r--r-- | lib/libc/gen/getcap.c | 14 | ||||
-rw-r--r-- | lib/libc/gen/getcwd.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/getgrent.c | 6 | ||||
-rw-r--r-- | lib/libc/gen/getpwent.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/opendir.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/scandir.c | 2 | ||||
-rw-r--r-- | lib/libc/gen/stringlist.c | 2 |
9 files changed, 19 insertions, 19 deletions
diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c index 02cad6c..da88ed1 100644 --- a/lib/libc/gen/fts-compat.c +++ b/lib/libc/gen/fts-compat.c @@ -881,7 +881,7 @@ fts_sort(sp, head, nitems) */ if (nitems > sp->fts_nitems) { sp->fts_nitems = nitems + 40; - if ((sp->fts_array = realloc(sp->fts_array, + if ((sp->fts_array = reallocf(sp->fts_array, (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) { sp->fts_nitems = 0; return (head); @@ -959,7 +959,7 @@ fts_palloc(sp, more) size_t more; { sp->fts_pathlen += more + 256; - sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen); + sp->fts_path = reallocf(sp->fts_path, (size_t)sp->fts_pathlen); return (sp->fts_path == NULL); } diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 02cad6c..da88ed1 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -881,7 +881,7 @@ fts_sort(sp, head, nitems) */ if (nitems > sp->fts_nitems) { sp->fts_nitems = nitems + 40; - if ((sp->fts_array = realloc(sp->fts_array, + if ((sp->fts_array = reallocf(sp->fts_array, (size_t)(sp->fts_nitems * sizeof(FTSENT *)))) == NULL) { sp->fts_nitems = 0; return (head); @@ -959,7 +959,7 @@ fts_palloc(sp, more) size_t more; { sp->fts_pathlen += more + 256; - sp->fts_path = realloc(sp->fts_path, (size_t)sp->fts_pathlen); + sp->fts_path = reallocf(sp->fts_path, (size_t)sp->fts_pathlen); return (sp->fts_path == NULL); } diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index 0295984..aaee0dd 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -344,7 +344,7 @@ getent(cap, len, db_array, fd, name, depth, nfield) pos = rp - record; newsize = r_end - record + BFRAG; - record = realloc(record, newsize); + record = reallocf(record, newsize); if (record == NULL) { errno = ENOMEM; if (myfd) @@ -484,7 +484,7 @@ tc_exp: { newsize = r_end - record + diff + BFRAG; tcpos = tcstart - record; tcposend = tcend - record; - record = realloc(record, newsize); + record = reallocf(record, newsize); if (record == NULL) { errno = ENOMEM; if (myfd) @@ -524,7 +524,7 @@ tc_exp: { *len = rp - record - 1; /* don't count NUL */ if (r_end > rp) if ((record = - realloc(record, (size_t)(rp - record))) == NULL) { + reallocf(record, (size_t)(rp - record))) == NULL) { errno = ENOMEM; return (-2); } @@ -867,7 +867,7 @@ cgetstr(buf, cap, str) if (m_room == 0) { size_t size = mp - mem; - if ((mem = realloc(mem, size + SFRAG)) == NULL) + if ((mem = reallocf(mem, size + SFRAG)) == NULL) return (-2); m_room = SFRAG; mp = mem + size; @@ -881,7 +881,7 @@ cgetstr(buf, cap, str) * Give back any extra memory and return value and success. */ if (m_room != 0) - if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) + if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL) return (-2); *str = mem; return (len); @@ -940,7 +940,7 @@ cgetustr(buf, cap, str) if (m_room == 0) { size_t size = mp - mem; - if ((mem = realloc(mem, size + SFRAG)) == NULL) + if ((mem = reallocf(mem, size + SFRAG)) == NULL) return (-2); m_room = SFRAG; mp = mem + size; @@ -954,7 +954,7 @@ cgetustr(buf, cap, str) * Give back any extra memory and return value and success. */ if (m_room != 0) - if ((mem = realloc(mem, (size_t)(mp - mem))) == NULL) + if ((mem = reallocf(mem, (size_t)(mp - mem))) == NULL) return (-2); *str = mem; return (len); diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index fae252d..8d57e6c 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -182,7 +182,7 @@ getcwd(pt, size) * possible component name, plus a trailing NULL. */ if (bup + 3 + MAXNAMLEN + 1 >= eup) { - if ((up = realloc(up, upsize *= 2)) == NULL) + if ((up = reallocf(up, upsize *= 2)) == NULL) goto err; bup = up; eup = up + upsize; diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 26069c6..5b5c9da 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -266,7 +266,7 @@ grscan(search, gid, name) maxlinelength >= MAXLINELENGTHLIMIT) return(0); - if ((line = (char *)realloc(line, + if ((line = (char *)reallocf(line, sizeof(char) * (maxlinelength + MAXLINELENGTH))) == NULL) return(0); @@ -381,7 +381,7 @@ grscan(search, gid, name) for (m = members; ; bp++) { if (m == (members + maxgrp - 1)) { if ((members = (char **) - realloc(members, + reallocf(members, sizeof(char **) * (maxgrp + MAXGRP))) == NULL) return(0); @@ -439,7 +439,7 @@ _gr_breakout_yp(struct group *gr, char *result) for (m = members; ; s++) { if (m == members + maxgrp - 1) { - if ((members = (char **)realloc(members, + if ((members = (char **)reallocf(members, sizeof(char **) * (maxgrp + MAXGRP))) == NULL) return(0); m = members + maxgrp - 1; diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index b26b927..02ec190 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -287,7 +287,7 @@ __hashpw(key) /* Increase buffer size for long lines if necessary. */ if (data.size > max) { max = data.size + 1024; - if (!(line = realloc(line, max))) + if (!(line = reallocf(line, max))) return(0); } diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 73da108..ff01646 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -137,7 +137,7 @@ __opendir2(name, flags) if (space < DIRBLKSIZ) { space += incr; len += incr; - buf = realloc(buf, len); + buf = reallocf(buf, len); if (buf == NULL) goto fail; ddptr = buf + (len - space); diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index e6e8408..8a8b7d2 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -109,7 +109,7 @@ scandir(dirname, namelist, select, dcomp) if (fstat(dirp->dd_fd, &stb) < 0) return(-1); /* just might have grown */ arraysz = stb.st_size / 12; - names = (struct dirent **)realloc((char *)names, + names = (struct dirent **)reallocf((char *)names, arraysz * sizeof(struct dirent *)); if (names == NULL) return(-1); diff --git a/lib/libc/gen/stringlist.c b/lib/libc/gen/stringlist.c index 57c4d91..bb74919 100644 --- a/lib/libc/gen/stringlist.c +++ b/lib/libc/gen/stringlist.c @@ -72,7 +72,7 @@ sl_add(sl, name) { if (sl->sl_cur == sl->sl_max - 1) { sl->sl_max += _SL_CHUNKSIZE; - sl->sl_str = realloc(sl->sl_str, sl->sl_max * sizeof(char *)); + sl->sl_str = reallocf(sl->sl_str, sl->sl_max * sizeof(char *)); if (sl->sl_str == NULL) err(1, "stringlist: %m"); } |