Browse Source

opencl: check if gpus.kernelname has to be free()'d before setting.

In this case it doesn't, since the function is only used for config
parsing (I hope). Add the check to prevent a memory leak, just in
case this changes in the future.

TODO: Option parsing functions should really be moved elsewhere and
renamed appropriately, like set_opt_kernel() or config_set_kernel(),
if config parsing is to remain as-is. It will probably change
drastically, so leaving as-is for now.
build-mingw
Noel Maersk 11 years ago
parent
commit
bc9b313e9c
  1. 18
      driver-opencl.c

18
driver-opencl.c

@ -203,16 +203,26 @@ char *set_kernel(char *arg)
if (nextptr == NULL) if (nextptr == NULL)
return "Invalid parameters for set kernel"; return "Invalid parameters for set kernel";
gpus[device++].kernelname = strdup(nextptr); if (gpus[device].kernelname != NULL)
free(gpus[device].kernelname);
gpus[device].kernelname = strdup(nextptr);
device++;
while ((nextptr = strtok(NULL, ",")) != NULL) while ((nextptr = strtok(NULL, ",")) != NULL) {
gpus[device++].kernelname = strdup(nextptr); if (gpus[device].kernelname != NULL)
free(gpus[device].kernelname);
gpus[device].kernelname = strdup(nextptr);
device++;
}
/* If only one kernel name provided, use same for all GPUs. */ /* If only one kernel name provided, use same for all GPUs. */
if (device == 1) { if (device == 1) {
for (i = device; i < MAX_GPUDEVICES; i++) for (i = device; i < MAX_GPUDEVICES; i++) {
if (gpus[i].kernelname != NULL)
free(gpus[i].kernelname);
gpus[i].kernelname = strdup(gpus[0].kernelname); gpus[i].kernelname = strdup(gpus[0].kernelname);
} }
}
return NULL; return NULL;
} }

Loading…
Cancel
Save