try to free mem as soon as possible
This commit is contained in:
parent
fb65cda40f
commit
e873fd637d
|
@ -3,6 +3,7 @@ MODULES = $(EMHOME)/modules
|
||||||
INSTALL = $(MODULES)/install
|
INSTALL = $(MODULES)/install
|
||||||
COMPARE = $(MODULES)/compare
|
COMPARE = $(MODULES)/compare
|
||||||
CFLAGS = -O
|
CFLAGS = -O
|
||||||
|
AR = ar
|
||||||
|
|
||||||
OBJECTS = AtEoIF.o\
|
OBJECTS = AtEoIF.o\
|
||||||
AtEoIT.o
|
AtEoIT.o
|
||||||
|
@ -10,7 +11,7 @@ OBJECTS = AtEoIF.o\
|
||||||
all: libinput.a
|
all: libinput.a
|
||||||
|
|
||||||
libinput.a: $(OBJECTS)
|
libinput.a: $(OBJECTS)
|
||||||
ar cr libinput.a $(OBJECTS)
|
$(AR) cr libinput.a $(OBJECTS)
|
||||||
-sh -c 'ranlib libinput.a'
|
-sh -c 'ranlib libinput.a'
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
|
|
|
@ -111,7 +111,6 @@ readfile(fd, fn, size, pbuf)
|
||||||
((unsigned) (*size + 1) != (*size + 1))
|
((unsigned) (*size + 1) != (*size + 1))
|
||||||
||
|
||
|
||||||
!(*pbuf = malloc((unsigned) (*size + 1)))) {
|
!(*pbuf = malloc((unsigned) (*size + 1)))) {
|
||||||
sys_close(fd);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
|
@ -119,11 +118,9 @@ readfile(fd, fn, size, pbuf)
|
||||||
||
|
||
|
||||||
*size != rsize
|
*size != rsize
|
||||||
) {
|
) {
|
||||||
sys_close(fd);
|
|
||||||
free(*pbuf);
|
free(*pbuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sys_close(fd);
|
|
||||||
(*pbuf)[*size] = '\0'; /* invoke loadbuf() at end */
|
(*pbuf)[*size] = '\0'; /* invoke loadbuf() at end */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -181,17 +178,6 @@ pop_bh()
|
||||||
{
|
{
|
||||||
register struct buffer_header *bh = head;
|
register struct buffer_header *bh = head;
|
||||||
|
|
||||||
if (bh->bh_fd) { /* unstack a file */
|
|
||||||
#ifndef INP_READ_IN_ONE
|
|
||||||
struct i_buf *ib;
|
|
||||||
|
|
||||||
ib = i_ptr->next;
|
|
||||||
free((char *) i_ptr);
|
|
||||||
i_ptr = ib;
|
|
||||||
#else INP_READ_IN_ONE
|
|
||||||
free(bh->bh_text);
|
|
||||||
#endif INP_READ_IN_ONE
|
|
||||||
}
|
|
||||||
|
|
||||||
bh = bh->next;
|
bh = bh->next;
|
||||||
free((char *) head);
|
free((char *) head);
|
||||||
|
@ -356,40 +342,51 @@ loadbuf()
|
||||||
return EOI;
|
return EOI;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ipp < &(bh->bh_text[bh->bh_size])) {
|
if (!bh->bh_eofreturned) {
|
||||||
|
if (_ipp < &(bh->bh_text[bh->bh_size])) {
|
||||||
/* a genuine '\0' character has been seen */
|
/* a genuine '\0' character has been seen */
|
||||||
return '\0';
|
return '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
FromFile = (bh->bh_fd != 0);
|
FromFile = (bh->bh_fd != 0);
|
||||||
|
|
||||||
#ifndef INP_READ_IN_ONE
|
#ifndef INP_READ_IN_ONE
|
||||||
if (FromFile) {
|
if (FromFile && bh->bh_size > 0) {
|
||||||
#if INP_PUSHBACK > 1
|
#if INP_PUSHBACK > 1
|
||||||
register char *so = &(bh->bh_text[bh->bh_size]);
|
register char *so = &(bh->bh_text[bh->bh_size]);
|
||||||
register char *de = bh->bh_text;
|
register char *de = bh->bh_text;
|
||||||
register int i = INP_NPUSHBACK - 1;
|
register int i = INP_NPUSHBACK - 1;
|
||||||
|
|
||||||
while (i-- > 0) {
|
while (i-- > 0) {
|
||||||
/* make sure PushBack will work */
|
/* make sure PushBack will work */
|
||||||
*--de = *--so;
|
*--de = *--so;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (
|
if ( readblock(bh->bh_fd, bh->bh_text, &(bh->bh_size))
|
||||||
readblock(bh->bh_fd, bh->bh_text, &(bh->bh_size))
|
&&
|
||||||
&&
|
bh->bh_size > 0
|
||||||
bh->bh_size > 0
|
) {
|
||||||
) {
|
_ipp = bh->bh_text;
|
||||||
_ipp = bh->bh_text;
|
return *_ipp++;
|
||||||
return *_ipp++;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif not INP_READ_IN_ONE
|
#endif not INP_READ_IN_ONE
|
||||||
|
if (FromFile && bh->bh_fd != STDIN) sys_close(bh->bh_fd);
|
||||||
|
|
||||||
if (!bh->bh_eofreturned) {
|
if (bh->bh_fd) { /* unstack a file */
|
||||||
|
#ifndef INP_READ_IN_ONE
|
||||||
|
struct i_buf *ib;
|
||||||
|
|
||||||
|
ib = i_ptr->next;
|
||||||
|
free((char *) i_ptr);
|
||||||
|
i_ptr = ib;
|
||||||
|
#else INP_READ_IN_ONE
|
||||||
|
free(bh->bh_text);
|
||||||
|
#endif INP_READ_IN_ONE
|
||||||
|
}
|
||||||
bh->bh_eofreturned = 1;
|
bh->bh_eofreturned = 1;
|
||||||
_ipp--;
|
_ipp = "";
|
||||||
if (FromFile) {
|
if (FromFile) {
|
||||||
if (AtEoIF()) return EOI;
|
if (AtEoIF()) return EOI;
|
||||||
}
|
}
|
||||||
|
@ -398,10 +395,6 @@ loadbuf()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef INP_READ_IN_ONE
|
|
||||||
if (FromFile && bh->bh_fd != STDIN) sys_close(bh->bh_fd);
|
|
||||||
#endif not INP_READ_IN_ONE
|
|
||||||
|
|
||||||
if (pop_bh()) {
|
if (pop_bh()) {
|
||||||
if (*_ipp) return *_ipp++;
|
if (*_ipp) return *_ipp++;
|
||||||
return loadbuf();
|
return loadbuf();
|
||||||
|
|
Loading…
Reference in a new issue