Skip to content

Fix refcounting in px_proxy_factory_copy (#280)#282

Merged
janbrummer merged 3 commits intolibproxy:mainfrom
smcv:issue280
Apr 2, 2024
Merged

Fix refcounting in px_proxy_factory_copy (#280)#282
janbrummer merged 3 commits intolibproxy:mainfrom
smcv:issue280

Conversation

@smcv
Copy link
Copy Markdown
Contributor

@smcv smcv commented Feb 27, 2024

smcv added 3 commits February 27, 2024 12:30
The second argument to g_boxed_copy() is meant to be a pointer to the
boxed instance itself, not a pointer to a pointer to the boxed instance.
For example, `g_boxed_copy (G_TYPE_STRV, environ)` is correct (equivalent
to g_strdupv() in this case), but `g_boxed_copy (G_TYPE_STRV, &environ)`
would be incorrect. The same principle applies here.

The test passed despite this because self->pf and
&self->pf happen to both be pointer-sized, and as a result of
libproxy#280, the data that is pointed
to was copied byte-by-byte but not otherwise used; but this will no
longer be true when libproxy#280 is fixed, so the test needs fixing first.

Signed-off-by: Simon McVittie <smcv@debian.org>
Otherwise there is no guarantee that the object will continue to exist
after the original factory is destroyed, and both the copy and the
original factory will try to unref it when destroyed, which is a
programming error.

Resolves: libproxy#280
Signed-off-by: Simon McVittie <smcv@debian.org>
Previously the copy was never freed, which hid the bugs fixed by the
previous commits.

Reproduces: libproxy#280
Signed-off-by: Simon McVittie <smcv@debian.org>
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.70%. Comparing base (dff9a60) to head (e946e65).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #282      +/-   ##
==========================================
+ Coverage   72.67%   72.70%   +0.03%     
==========================================
  Files          16       16              
  Lines         849      850       +1     
  Branches      241      241              
==========================================
+ Hits          617      618       +1     
  Misses        137      137              
  Partials       95       95              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@janbrummer
Copy link
Copy Markdown
Contributor

Ohh, there is a lot more broken in the current code. The last argument to G_DEFINE_BOXED_TYPE is the free function and i for some reason used it as new function...

Could you please fix it as well?

@janbrummer
Copy link
Copy Markdown
Contributor

@smcv Are you going to update your PR soon?

@janbrummer
Copy link
Copy Markdown
Contributor

Actually i'll merge it as it and will do a follow up PR. Thanks for your contribution!

@janbrummer janbrummer merged commit 4e6202d into libproxy:main Apr 2, 2024
sir-xw pushed a commit to openkylin/libproxy that referenced this pull request Apr 22, 2025
The second argument to g_boxed_copy() is meant to be a pointer to the
boxed instance itself, not a pointer to a pointer to the boxed instance.
For example, `g_boxed_copy (G_TYPE_STRV, environ)` is correct (equivalent
to g_strdupv() in this case), but `g_boxed_copy (G_TYPE_STRV, &environ)`
would be incorrect. The same principle applies here.

The test passed despite this because self->pf and
&self->pf happen to both be pointer-sized, and as a result of
libproxy/libproxy#280, the data that is pointed
to was copied byte-by-byte but not otherwise used; but this will no
longer be true when #280 is fixed, so the test needs fixing first.

Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: libproxy/libproxy#282

Gbp-Pq: Name tests-Copy-pxProxyFactory-correctly.patch
sir-xw pushed a commit to openkylin/libproxy that referenced this pull request Apr 22, 2025
Otherwise there is no guarantee that the object will continue to exist
after the original factory is destroyed, and both the copy and the
original factory will try to unref it when destroyed, which is a
programming error.

Bug: libproxy/libproxy#280
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: libproxy/libproxy#282

Gbp-Pq: Name px_proxy_factory_copy-Add-a-new-reference-to-the-manager.patch
sir-xw pushed a commit to openkylin/libproxy that referenced this pull request Apr 22, 2025
Previously the copy was never freed, which hid the bugs fixed by the
previous commits.

Bug: libproxy/libproxy#280
Signed-off-by: Simon McVittie <smcv@debian.org>
Forwarded: libproxy/libproxy#282

Gbp-Pq: Name tests-Don-t-leak-the-copied-pxProxyFactory.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

px_proxy_factory_copy doesn't increment refcount of the underlying proxy manager

2 participants