Skip to content

Commit 561bee9

Browse files
CopilotJohnAmadis
andcommitted
Fix memory management and initialization issues from code review
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 6778ecf commit 561bee9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/dmdevfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fopen, (dmfsi_context_t ctx,
244244
}
245245

246246
handle->driver = driver_node;
247-
handle->path = path;
247+
handle->path = Dmod_StrDup(path);
248248
handle->mode = mode;
249249
handle->attr = attr;
250250

@@ -278,6 +278,12 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, int, _fclose, (dmfsi_context_t ctx
278278
dmdrvi_close(handle->driver->driver_context, handle->driver_handle);
279279
}
280280

281+
// Free the path string that was duplicated in fopen
282+
if(handle->path)
283+
{
284+
Dmod_Free((void*)handle->path);
285+
}
286+
281287
Dmod_Free(handle);
282288
return DMFSI_OK;
283289
}
@@ -441,7 +447,7 @@ dmod_dmfsi_dif_api_declaration( 1.0, dmdevfs, long, _size, (dmfsi_context_t ctx,
441447
file_handle_t* handle = (file_handle_t*)fp;
442448

443449
// Try to get size from stat if available
444-
dmdrvi_stat_t stat;
450+
dmdrvi_stat_t stat = {0};
445451
int result = driver_stat(handle->driver, handle->path, &stat);
446452
if(result == 0)
447453
{

0 commit comments

Comments
 (0)