File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -281,13 +281,27 @@ static int tmpfs_realloc_file(FAR struct tmpfs_file_s *tfo,
281
281
* zero.
282
282
*/
283
283
284
- if (newsize > 0 )
284
+ if (newsize == 0 )
285
+ {
286
+ /* Free the file object */
287
+
288
+ kmm_free (tfo -> tfo_data );
289
+ tfo -> tfo_data = NULL ;
290
+ tfo -> tfo_alloc = 0 ;
291
+ tfo -> tfo_size = 0 ;
292
+ return OK ;
293
+ }
294
+ else if (newsize > 0 )
285
295
{
286
296
/* Otherwise, don't realloc unless the object has shrunk by a
287
297
* lot.
288
298
*/
289
299
290
300
delta = tfo -> tfo_alloc - newsize ;
301
+
302
+ /* We should make sure the shrunked memory be zero */
303
+
304
+ memset (tfo -> tfo_data + newsize , 0 , delta );
291
305
if (delta <= CONFIG_FS_TMPFS_FILE_FREEGUARD )
292
306
{
293
307
/* Hasn't shrunk enough.. Return doing nothing for now */
You can’t perform that action at this time.
0 commit comments