Checking memory allocation return values helps prevent crashes

svn path=/trunk/; revision=20316
This commit is contained in:
Gé van Geldorp 2005-12-23 20:47:54 +00:00
parent 9851ee0b33
commit 7ca33cb6d6
2 changed files with 25 additions and 4 deletions

View file

@ -304,9 +304,12 @@ union mcluster {
#ifdef __REACTOS__
#define MCLGET(m, how) { \
OS_DbgPrint(OSK_MID_TRACE,("(MCLGET) m = %x\n", m)); \
(m)->m_data = (m)->m_ext.ext_buf = malloc(MCLBYTES); \
(m)->m_flags |= M_EXT; \
(m)->m_ext.ext_size = MCLBYTES; \
(m)->m_ext.ext_buf = malloc(MCLBYTES); \
if ((m)->m_ext.ext_buf != NULL) { \
(m)->m_data = (m)->m_ext.ext_buf; \
(m)->m_flags |= M_EXT; \
(m)->m_ext.ext_size = MCLBYTES; \
} \
}
#define MCLFREE(p) { \

View file

@ -366,8 +366,17 @@ sendit:
#ifdef __REACTOS__
if( OtcpEvent.PacketSend ) {
struct mbuf *new_m;
MGET( new_m, M_DONTWAIT, 0 );
new_m = m_get( M_DONTWAIT, 0 );
if ( NULL == new_m ) {
error = ENOBUFS;
goto done;
}
MCLGET( new_m, M_DONTWAIT );
if (0 == (new_m->m_flags & M_EXT)) {
m_free( new_m );
error = ENOBUFS;
goto done;
}
m_copydata( m, 0, htons(ip->ip_len), new_m->m_data );
new_m->m_len = htons(ip->ip_len);
error = OtcpEvent.PacketSend( OtcpEvent.ClientData,
@ -498,7 +507,16 @@ sendorfree:
if( error == 0 && OtcpEvent.PacketSend ) {
struct mbuf *new_m;
MGET( new_m, M_DONTWAIT, 0 );
if ( NULL == new_m ) {
error = ENOBUFS;
goto done;
}
MCLGET( new_m, M_DONTWAIT );
if (0 == (new_m->m_flags & M_EXT)) {
m_free( new_m );
error = ENOBUFS;
goto done;
}
m_copydata( m, 0, htons(ip->ip_len), new_m->m_data );
new_m->m_len = htons(ip->ip_len);
error = OtcpEvent.PacketSend( OtcpEvent.ClientData,