Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

buflib: Allow handle to be freed entirely during the shrink callback.

Change-Id: I3a069dcb99bbd4022faf37596b03beb926d2ea82
Reviewed-on: http://gerrit.rockbox.org/480
Reviewed-by: Thomas Martitz <kugel@rockbox.org>
Tested-by: Thomas Martitz <kugel@rockbox.org>

+10 -4
+10 -4
firmware/buflib.c
··· 165 165 union buflib_data* name_field = 166 166 (union buflib_data*)buflib_get_name(ctx, handle); 167 167 168 - return name_field - 3; 168 + return name_field ? name_field - 3 : NULL; 169 169 } 170 170 171 171 /* Shrink the handle table, returning true if its size was reduced, false if ··· 353 353 ret = this[2].ops->shrink_callback(handle, shrink_hints, 354 354 data, (char*)(this+this->val)-data); 355 355 result |= (ret == BUFLIB_CB_OK); 356 - /* this might have changed in the callback (if 357 - * it shrinked from the top), get it again */ 356 + /* 'this' might have changed in the callback (if it shrinked 357 + * from the top or even freed the handle), get it again */ 358 358 this = handle_to_block(ctx, handle); 359 + /* The handle was possibly be freed in the callback, 360 + * re-run the loop with the handle before */ 361 + if (!this) 362 + this = before; 359 363 /* could also change with shrinking from back */ 360 - if (last) 364 + else if (last) 361 365 ctx->alloc_end = this + this->val; 362 366 } 363 367 } ··· 780 784 const char* buflib_get_name(struct buflib_context *ctx, int handle) 781 785 { 782 786 union buflib_data *data = ALIGN_DOWN(buflib_get_data(ctx, handle), sizeof (*data)); 787 + if (!data) 788 + return NULL; 783 789 size_t len = data[-1].val; 784 790 if (len <= 1) 785 791 return NULL;