Skip to content

Commit

Permalink
fix potential memory leak in sbuf_split_at
Browse files Browse the repository at this point in the history
fixes daanx#19
  • Loading branch information
thomcc committed Jun 6, 2024
1 parent c9310ae commit 4308f02
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stringbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,9 @@ ic_private ssize_t sbuf_insert_at_n(stringbuf_t* sbuf, const char* s, ssize_t n,
}

ic_private stringbuf_t* sbuf_split_at( stringbuf_t* sb, ssize_t pos ) {
if (pos < 0) return NULL;
stringbuf_t* res = sbuf_new(sb->mem);
if (res==NULL || pos < 0) return NULL;
if (res==NULL) return NULL;
if (pos < sb->count) {
sbuf_append_n(res, sb->buf + pos, sb->count - pos);
sb->count = pos;
Expand Down

0 comments on commit 4308f02

Please sign in to comment.