*/
#include "suricata-common.h"
+#include "stream-tcp.h"
#include "stream-tcp-private.h"
#include "stream-tcp-sack.h"
#include "util-unittest.h"
}
#endif /* DEBUG */
+static StreamTcpSackRecord *StreamTcpSackRecordAlloc(void) {
+ if (StreamTcpCheckMemcap((uint32_t)sizeof(StreamTcpSackRecord)) == 0)
+ return NULL;
+
+ StreamTcpSackRecord *rec = SCMalloc(sizeof(*rec));
+ if (unlikely(rec == NULL))
+ return NULL;
+
+ StreamTcpIncrMemuse((uint64_t)sizeof(*rec));
+ return rec;
+}
+
+static void StreamTcpSackRecordFree(StreamTcpSackRecord *rec) {
+ SCFree(rec);
+ StreamTcpDecrMemuse((uint64_t)sizeof(*rec));
+}
+
/**
* \brief insert a SACK range
*
if (SEQ_LT(re, rec->le)) {
SCLogDebug("SEQ_LT(re, rec->le)");
// entirely before, prepend
- StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord));
+ StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) {
SCReturnInt(-1);
}
SCLogDebug("implied le > rec->re");
if (rec->next == NULL) {
SCLogDebug("rec->next == NULL");
- StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord));
+ StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) {
SCReturnInt(-1);
}
SCLogDebug("implied rec->next != NULL");
if (SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)) {
SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_LT(re, rec->next->le)");
- StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord));
+ StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) {
SCReturnInt(-1);
}
} else if (SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)) {
SCLogDebug("SEQ_LT(le, rec->next->le) && SEQ_GEQ(re, rec->next->le)");
- StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord));
+ StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) {
SCReturnInt(-1);
}
}
} else {
SCLogDebug("implied empty list");
- StreamTcpSackRecord *stsr = SCMalloc(sizeof(StreamTcpSackRecord));
+ StreamTcpSackRecord *stsr = StreamTcpSackRecordAlloc();
if (unlikely(stsr == NULL)) {
SCReturnInt(-1);
}
while (rec != NULL) {
next = rec->next;
- SCFree(rec);
+ StreamTcpSackRecordFree(rec);
rec = next;
}