Second part, file is basically a dangling pointer

at this stage, better using the stack for this purpose.
This commit is contained in:
David Carlier 2018-07-19 13:32:05 +01:00
parent e755fd55b9
commit 0189b83010

4
vm.c
View File

@ -10771,8 +10771,10 @@ static int vm_builtin_import(ph7_context *pCtx, int nArg, ph7_value **apArg) {
/* Zero the module entry */ /* Zero the module entry */
SyZero(&pModule, sizeof(VmModule)); SyZero(&pModule, sizeof(VmModule));
SyStringInitFromBuf(&pModule.sName, zStr, nLen); SyStringInitFromBuf(&pModule.sName, zStr, nLen);
unsigned char bfile[255] = {0};
unsigned char *file; unsigned char *file;
snprintf(file, 255, "./%s.lib", zStr); snprintf(bfile, sizeof(bfile) - 1, "./%s.lib", zStr);
file = bfile;
SyStringInitFromBuf(&pModule.sFile, file, nLen); SyStringInitFromBuf(&pModule.sFile, file, nLen);
pModule.pHandle = dlopen(pModule.sFile.zString, RTLD_LAZY); pModule.pHandle = dlopen(pModule.sFile.zString, RTLD_LAZY);
if(!pModule.pHandle) { if(!pModule.pHandle) {