MULE 0.0.1
Multi-Use Library Essentials
Loading...
Searching...
No Matches
11_double_free.c

A bug on purpose. Copying a Str struct makes two owners of one buffer.

/* Bug on purpose: copying a Str struct makes two owners of one buffer. */
#include "mem/mem.c"
#include "str/str.c"
#include <stdlib.h>
int main(void) {
Str a = { 0 };
if (!str_append_cstr(&a, "Dunya")) return EXIT_FAILURE;
Str b = a; /* copies the pointer, not the bytes */
str_free(&a);
str_free(&b); /* frees the same buffer again */
return EXIT_SUCCESS;
}
void str_free(Str *s)
Free the buffer and reset s to the zero state.
Definition str.c:50
bool str_append_cstr(Str *s, const char *cstr)
Append cstr.
Definition str.c:119
Owned, growable byte string.
Definition str.h:64