Skip to content
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

[rtextures] LoadImageAnimFromMemory() warning for free #3704

Closed
4 tasks done
ghost opened this issue Jan 5, 2024 · 1 comment
Closed
4 tasks done

[rtextures] LoadImageAnimFromMemory() warning for free #3704

ghost opened this issue Jan 5, 2024 · 1 comment

Comments

@ghost
Copy link

ghost commented Jan 5, 2024

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

While compiling the current master branch (eb6dcab) there's the following warning (which I didn't notice when I submitted the previous warning fix at #3686 because I had SUPPORT_FILEFORMAT_GIF disabled at the time):

In file included from rtextures.c:64:
rtextures.c: In function ‘LoadImageAnimFromMemory’:
rtextures.c:463:21: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  463 |             RL_FREE(fileData);
      |                     ^~~~~~~~
raylib.h:136:38: note: in definition of macro ‘RL_FREE’
  136 |     #define RL_FREE(ptr)        free(ptr)
      |                                      ^~~
In file included from rtextures.c:76:
/usr/include/stdlib.h:555:25: note: expected ‘void *’ but argument is of type ‘const unsigned char *’
  555 | extern void free (void *__ptr) __THROW;
      |                   ~~~~~~^~~~~

Proposed solution

I see two ways to fix this:

  • A. Removing const (L446, L1305) from the fileData parameter and leaving the RL_FREE(fileData); (L463) there.

  • B. Or leaving the const (L446, L1305) there and removing the RL_FREE(fileData); (L463).

I think B would be the better approach, leaving to the user to free his fileData when he no longer needs it. As it's right now, it assumes the file data should be freed regarless, which is not the case on the similar LoadImageFromMemory() (L482).

@raysan5 Which's your prefered approach?

References

Environment

  • PLATFORM_DESKTOP, Linux (Mint 21.1 64-bit).

Code Example

cd raylib-master/src/
make PLATFORM=PLATFORM_DESKTOP
@raysan5
Copy link
Owner

raysan5 commented Jan 5, 2024

@ubkp Oh! Good catch! Thanks for reporting! That function was added very recently and I didn't notice this issue!

Indeed, the RL_FREE(fileData) shouldn't be there! When dealing with memory data passed to the function, the caller is the owner of that data, the function should not touch it!

Just reviewed it!

@raysan5 raysan5 closed this as completed Jan 5, 2024
raysan5 added a commit that referenced this issue Jan 5, 2024
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

No branches or pull requests

1 participant