Skip to content

Commit 622acad

Browse files
committed
fix memory pioCopyWithFilters with new fobj_alloc_temp
1 parent 8393388 commit 622acad

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/fu_util/fo_obj.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ extern fobjBool* fobj_bool(bool f);
479479
#define kls__fobjBool mth(fobjRepr, fobjFormat)
480480
fobj_klass(fobjBool);
481481

482+
/*
483+
* Allocate temporary blob.
484+
* It could be anything, and it will be automatically released.
485+
*/
486+
static inline void* fobj_alloc_temp(size_t buf_size);
487+
/* get object pointer for temporary blob */
488+
static inline fobj_t fobj_temp2obj(void* temp);
489+
#define fobj_temp_save(ptr) $save(fobj_temp2obj(ptr))
490+
#define fobj_temp_result(ptr) $result(fobj_temp2obj(ptr))
491+
#define fobj_temp_return(ptr) $return(fobj_temp2obj(ptr))
492+
482493
/**********************************
483494
* kv
484495
*/

src/fu_util/impl/fo_impl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ fobj_klass_handle(fobjInt);
13411341
fobj_klass_handle(fobjUInt);
13421342
fobj_klass_handle(fobjFloat);
13431343
fobj_klass_handle(fobjBool);
1344+
fobj_klass_handle(fobjTempBuffer);
13441345

13451346
void
13461347
fobj_init(void) {

src/fu_util/impl/fo_impl2.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,31 @@ fobj_errsrc(err_i err) {
234234
#define fobj__transform_fokv(...) \
235235
fm_eval_tuples_comma(fobj__transform_fokv_do, __VA_ARGS__)
236236

237+
/**********************************
238+
* Temp Buffer - "anything" you want to be automatically cleared
239+
*/
240+
typedef struct fobjTempBuffer {
241+
char buf[1];
242+
} fobjTempBuffer;
243+
#define kls__fobjTempBuffer varsized(buf)
244+
fobj_klass(fobjTempBuffer);
245+
246+
247+
static inline void*
248+
fobj_alloc_temp(size_t buf_size)
249+
{
250+
return fobj_alloc_sized(fobjTempBuffer, buf_size)->buf;
251+
}
252+
253+
static inline fobj_t
254+
fobj_temp2obj(void* temp)
255+
{
256+
/*
257+
* It looks dumb for the moment.
258+
* But in future object header will not be hidden, therefore
259+
* it will be meaningful.
260+
*/
261+
return (fobj_t)((char*)temp - offsetof(fobjTempBuffer, buf));
262+
}
263+
237264
#endif // FOBJ_OBJ_PRIV2_H

src/utils/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5634,7 +5634,7 @@ pioCopyWithFilters(pioWriteFlush_i dest, pioRead_i src,
56345634
for (i = nfilters - 1; i >= 0; i--)
56355635
dest = pioWrapWriteFilter(dest, filters[i], OUT_BUF_SIZE);
56365636

5637-
buf = ft_malloc(OUT_BUF_SIZE);
5637+
buf = fobj_alloc_temp(OUT_BUF_SIZE);
56385638

56395639
for (;;)
56405640
{

0 commit comments

Comments
 (0)