FFstrbuf: don't free string literals

This commit is contained in:
李通洲 2022-09-23 15:10:50 +08:00
parent 5498b0b042
commit 484264027c
No known key found for this signature in database
GPG Key ID: 3570F9F0F4410388
2 changed files with 6 additions and 0 deletions

View File

@ -549,6 +549,8 @@ uint16_t ffStrbufToUInt16(const FFstrbuf* strbuf, uint16_t defaultValue)
void ffStrbufDestroy(FFstrbuf* strbuf)
{
if(strbuf->allocated == 0) return;
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
strbuf->allocated = strbuf->length = 0;
free(strbuf->chars);

View File

@ -24,6 +24,10 @@ int main(int argc, char** argv)
FFstrbuf strbuf;
//destroy 0
ffStrbufInitA(&strbuf, 0);
ffStrbufDestroy(&strbuf);
//initA
ffStrbufInitA(&strbuf, 0);