You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I've used the arduino code for SCPI processing and it's working very well. Perhaps I'm not using it correctly, and I should say I'm no C expert but I think there's a memory leak in the way the code manages errors.
When an error is created by the application to place on the queue, the code 'malloc's some memory to create it. When it is popped off the queue, say to be displayed, that memory is not freed. When there is no error, a 'success' error is malloc(ed) and returned but again, the memory is not freed.
My consuming app is fairly simple and is based on your example meter.ino. However, my application does raise errors and loop() pops them off the queue until a success error is received. If I don't free() each error popped, the Arduino stops responding after approximately 10 - 12 processes of a IDN? command; If I free() each error then it seems to run indefinitely.
Here's my loop():
void loop()
{
char line_buffer[60];
unsigned char read_length;
struct scpi_error error;
while(1)
{
/* Read in a line and execute it. /
read_length = Serial.readBytesUntil('\n', line_buffer, 60);
if(read_length > 0)
{
scpi_execute_command(&ctx, line_buffer, read_length);
error = scpi_pop_error(&ctx);
while (error->id != 0) {
Serial.print(error->id);
Serial.print(": ");
Serial.println(error->description);
free( (void)error);
error = scpi_pop_error(&ctx);
}
free( (void*)error);
}
}
}
You can see the free() commands; comment those out and the Arduino grinds to a halt. Perhaps Errors should be returned as a linked list, like command, with a function to free_errors() like free_tokens().
Regards,
Andrew
The text was updated successfully, but these errors were encountered:
Hi,
I've used the arduino code for SCPI processing and it's working very well. Perhaps I'm not using it correctly, and I should say I'm no C expert but I think there's a memory leak in the way the code manages errors.
When an error is created by the application to place on the queue, the code 'malloc's some memory to create it. When it is popped off the queue, say to be displayed, that memory is not freed. When there is no error, a 'success' error is malloc(ed) and returned but again, the memory is not freed.
My consuming app is fairly simple and is based on your example meter.ino. However, my application does raise errors and loop() pops them off the queue until a success error is received. If I don't free() each error popped, the Arduino stops responding after approximately 10 - 12 processes of a IDN? command; If I free() each error then it seems to run indefinitely.
Here's my loop():
void loop()
{
char line_buffer[60];
unsigned char read_length;
struct scpi_error error;
while(1)
{
/* Read in a line and execute it. /
read_length = Serial.readBytesUntil('\n', line_buffer, 60);
if(read_length > 0)
{
scpi_execute_command(&ctx, line_buffer, read_length);
error = scpi_pop_error(&ctx);
while (error->id != 0) {
Serial.print(error->id);
Serial.print(": ");
Serial.println(error->description);
free( (void)error);
error = scpi_pop_error(&ctx);
}
free( (void*)error);
}
}
}
You can see the free() commands; comment those out and the Arduino grinds to a halt. Perhaps Errors should be returned as a linked list, like command, with a function to free_errors() like free_tokens().
Regards,
Andrew
The text was updated successfully, but these errors were encountered: