mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-31 08:54:19 +00:00
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.
This commit is contained in:
parent
18d9c648ba
commit
bc9b313e9c
@ -203,15 +203,25 @@ 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…
x
Reference in New Issue
Block a user