Skip to content

Commit f19f59b

Browse files
committed
Handle OOM errors gracefully in module search path addition
1 parent e2452d0 commit f19f59b

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

include/importer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void initImporter(Importer *importer);
2929
bool loadModule(Importer *importer, const char *moduleName, void** result);
3030

3131
// Add a directory to the module search path
32-
void addSearchPath(Importer *importer, const char *path);
32+
bool addSearchPath(Importer *importer, const char *path);
3333

3434
// Free importer resources
3535
void freeImporter(Importer *importer);

src/compiler/importer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ void initImporter(Importer *importer) {
2727
addSearchPath(importer, ".");
2828
}
2929

30-
void addSearchPath(Importer *importer, const char *path) {
30+
bool addSearchPath(Importer *importer, const char *path) {
3131
char** newPaths = (char**)realloc(importer->searchPaths, sizeof(char*) * (importer->pathCount + 1));
32-
if (!newPaths) return;
32+
if (!newPaths) return false;
3333
importer->searchPaths = newPaths;
3434

3535
// Duplicate string
3636
size_t len = strlen(path);
3737
char* pathCopy = (char*)malloc(len + 1);
38-
if (!pathCopy) return;
38+
if (!pathCopy) return false;
3939
strcpy(pathCopy, path);
4040

4141
importer->searchPaths[importer->pathCount++] = pathCopy;
42+
return true;
4243
}
4344

4445
bool loadModule(Importer *importer, const char *moduleName, void** result) {

0 commit comments

Comments
 (0)