streaming: improve error handling

util-streaming-buffer.c:205:5: warning: Potential leak of memory pointed to by 'sbb2' [unix.Malloc]
    BUG_ON(sbb2->offset < sbb->len);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./suricata-common.h:290:27: note: expanded from macro 'BUG_ON'
        #define BUG_ON(x) assert(!(x))
                          ^~~~~~~~~~~~
/usr/include/assert.h:99:28: note: expanded from macro 'assert'
     ? __ASSERT_VOID_CAST (0)                                           \
                           ^
1 warning generated.
pull/8761/head
Victor Julien 3 years ago
parent 999bf34257
commit 5f1651282d

@ -183,26 +183,28 @@ static int WARN_UNUSED SBBInit(StreamingBuffer *sb, uint32_t rel_offset, uint32_
}
sbb->offset = sb->stream_offset;
sbb->len = sb->buf_offset;
(void)SBB_RB_INSERT(&sb->sbb_tree, sbb);
sb->sbb_size = sbb->len;
sb->head = sbb;
StreamingBufferBlock *sbb2 = CALLOC(sb->cfg, 1, sizeof(*sbb2));
if (sbb2 == NULL) {
FREE(sb->cfg, sbb, sizeof(*sbb));
return -1;
}
sbb2->offset = sb->stream_offset + rel_offset;
sbb2->len = data_len;
sb->head = sbb;
sb->sbb_size = sbb->len + sbb2->len;
SBB_RB_INSERT(&sb->sbb_tree, sbb);
SBB_RB_INSERT(&sb->sbb_tree, sbb2);
SCLogDebug("sbb1 %"PRIu64", len %u, sbb2 %"PRIu64", len %u",
sbb->offset, sbb->len, sbb2->offset, sbb2->len);
sb->sbb_size += sbb2->len;
if (SBB_RB_INSERT(&sb->sbb_tree, sbb2) != NULL) {
FREE(sb->cfg, sbb2, sizeof(*sbb2));
return -1;
}
#ifdef DEBUG
SBBPrintList(sb);
#endif
BUG_ON(sbb2->offset < sbb->len);
return 0;
}
@ -222,7 +224,7 @@ static int WARN_UNUSED SBBInitLeadingGap(StreamingBuffer *sb, uint64_t offset, u
sb->head = sbb;
sb->sbb_size = sbb->len;
SBB_RB_INSERT(&sb->sbb_tree, sbb);
(void)SBB_RB_INSERT(&sb->sbb_tree, sbb);
SCLogDebug("sbb %"PRIu64", len %u",
sbb->offset, sbb->len);

Loading…
Cancel
Save