New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Potential bug: dangerous code: Remove std::move from Service API v2 macros #739
Comments
Calling this service was clearing out a global QString logPropagateArgs so that the second time the service is called an empty string is returned and after a call to this service any other code in the backend that uses logPropagateArgs will not find the value.
This macro looks like it generates inline code instead of a function call. |
As a test, I commented these lines that generate the std::move: mythtv/mythtv/libs/libmythbase/http/mythhttpservice.h Lines 76 to 81 in b9354c9
I also reversed the commit c92362e Everything builds correctly. I tested the Myth/GetBackendInfo call and that works OK, the logPropagateArgs do not get cleared I ran some large queries of GetProgramGuide several times. All works fine and there did not seem to be any memory leakage. Any problems with removing those lines and reverting c92362e? |
I think that I know what is wrong in line 81 of mythhttpservice.h There are two ways of copying a value without creating a temporary object that is later deleted. The first is to to define the setLogArg with a reference to a QString. The second is to define the setLogArg with a QString parameter, and then using std::move in the assignment to m_logArg. The temporary object is then moved to m_logArg. This is just as effient as the previous method. What goes wrong here in line 81 is that it has a reference to the QString as parameter and then it does the std::move to copy that reference to m_logArg. This then destroys the original QString. So instead of this: |
But, to answer your question
No problem, just go ahead. |
I'm ok with this fix. |
The Services API macros for generating the set methods use a std::move call to set values that are QString, QDateTime, QVariantMap, or QVariantList if the parameter is not const. This resulted in a bug where the logging parameters were cleared out by an API call to access backend information. see c92362e. If the parameter is defined as const, the object is copied.
There may be other cases where a value is inadvertently being lost due to the parameter not being defined as const.
Fix this by eliminating the std::move for QString and investigate whether it should be eliminated for the other types also.
Reference
mythtv/mythtv/libs/libmythbase/http/mythhttpservice.h
Line 81 in c92362e
The text was updated successfully, but these errors were encountered: